«^»
12.1. Accessing the Web Service provided by Amazon

12.1.1. Accessing and using Amazon's WSDL document

Amazon provide a number of web sites around the world (including www.amazon.co.uk). Many of these Amazon sites provide a Web Service.

There is information about Amazon Web Services at:
http://www.amazon.com/webservices/

The WSDL document for accessing the Web Service provided by the Amazon sites in UK and Germany is located at:
http://soap-eu.amazon.com/schemas3/AmazonWebServices.wsdl
and the WSDL document for the Amazon Web Services at its USA and Japan sites is located at:
http://soap.amazon.com/schemas3/AmazonWebServices.wsdl

12.1.2. Providing a console application that is a client of Amazon's Web Services

We can use one of the above WSDL documents to generate a proxy class for accessing the information stored at an Amazon site. You will get a proxy class called AmazonSearchService together with a number of supporting classes such as AsinRequest. The latter is used to generate a search for a particular product.

The following console application accesses the information stored at the www.amazon.co.uk site. An affliate of Amazon's site should set the tag field (of an AsinRequest object) to their affliate name. If you are not an Amazon affliate, you should set this field to "webservices-20". Whether or not you are an affliate, you still have to register with Amazon to use their Web Service. In the following code, my registration id has been replaced by "XXXXXXXXXXXXXX". Besides using the WSDL document that is appropriate for the particular Amazon site you wish to access, it is also necessary to set the locale field. In the following code, this field is set to uk. If your query only requires access to a small number of the available fields, you can set the type field to "lite": if instead you want all of the values, set this field to "heavy".

It seems it is part of the design of Amazon's Web Service to return null if a value is not available in time: it seems that their view is that it is better to be fast in providing some of the information rather than hanging around for all of it to become available.

0476: using AmazonSearchService = ConsoleAmazon.Proxy.AmazonSearchService;
0477: using AsinRequest         = ConsoleAmazon.Proxy.AsinRequest;
0478: using Console             = System.Console;
0479: using Details             = ConsoleAmazon.Proxy.Details;
0480: using ProductInfo         = ConsoleAmazon.Proxy.ProductInfo;
0481: namespace ConsoleAmazon
0482: {
0483:     public class Class1
0484:     {
0485:         public static void Main()
0486:         {
0487:             Console.Write("Type in an ISBN: ");
0488:             string tIsbnString = Console.ReadLine();
0489:             AmazonSearchService tAmazonSearchService = 
0490:                 new AmazonSearchService();
0491:             AsinRequest tAsinRequest = new AsinRequest();
0492:             tAsinRequest.tag = "webservices-20";
0493:             tAsinRequest.devtag = "XXXXXXXXXXXXXX";
0494:             tAsinRequest.asin = tIsbnString;
0495:             tAsinRequest.locale = "uk";
0496:             tAsinRequest.type = "heavy";
0497:             ProductInfo tProductInfo  = 
0498:                 tAmazonSearchService.AsinSearchRequest(tAsinRequest);
0499:             Details[] tDetailsArray = tProductInfo.Details;
0500:             Details tDetails = tDetailsArray[0];
0501:             Console.WriteLine(tDetails.ProductName);
0502:             Console.WriteLine(tDetails.ReleaseDate);
0503:             Console.WriteLine(tDetails.OurPrice);
0504:             Console.WriteLine(tDetails.ListPrice);
0505:             Console.WriteLine(tDetails.UsedPrice);
0506:             Console.WriteLine(tDetails.SalesRank);
0507:             Console.WriteLine(tDetails.Availability);
0508:             Console.WriteLine(tDetails.ImageUrlSmall);
0509:             Console.WriteLine(tDetails.ImageUrlMedium);
0510:             Console.WriteLine(tDetails.ImageUrlLarge);
0511:         }
0512:     }
0513: }