Amazon Web Services and .NET

Thanks to my new phone I am now a web surfing fool (or perhaps just a regular fool). However I've had one problem... I can't surf Amazon.com too well. While I occasionaly shop at Amazon.com I usually perfer to use it as a research tool too look up reviews of products I'm interested in, or just sometimes price compare. But I've not had much luck so far on my phone. The main site is too design heavy and slow to be practical on a phone. The PDA version doesn't render correctly on mobile explorer for some reason and the phone version is just way to limited and doesn't give me the information I want.

So I thought I would make my own version with the help of Amazon Web Services aka  E-Commerce Service  (ECS). I fired up VS and grabbed the latest WDSL. I checked the docs and built a simple wrapper for a basic search:

 

    public static Item[] Search( string keywords) {

      AWSECommerceService service = new AWSECommerceService();

      ItemSearchRequest request = new ItemSearchRequest();

      request.Power = "title:" + keywords;

      request.SearchIndex = "Books";

      request.ResponseGroup = new string[] { "Small" };

      request.Sort = "salesrank";

 

      ItemSearchRequest[] requests = new ItemSearchRequest[] {

  request };

     

      ItemSearch search = new ItemSearch();

      search.AssociateTag = "myassociatetag-20";

      search.SubscriptionId = Globals.AWSID;

      search.Request = requests;

     

      try {

        ItemSearchResponse response = service.ItemSearch( search );

 

        Items info = response.Items[ 0 ];

        return info.Item;

     

      }

      catch (Exception ex) {

         Console.WriteLine( ex.ToString() );

      }

      return null;

    }

Btw, this article helped get me going. Everything looked great and I built a demo app to try it out. I immediately ran into a problem. It turns out that the WDSL provided by Amazon or the code generated  but .NET has a few problems with it. These led me to some wonderful and cryptic error messages like:

An unhandled exception of type 'System.InvalidOperationException' occurred in system.web.services.dll
Additional information: Method AWSECommerceService.CustomerContentSearch can not be reflected.

and

Types CustomerReviews1 and CustomerReviews both use the XML type name, CustomerReviews, from namespace http://webservices.amazon.com/AWSECommerceService/2004-10-19. Use XML attributes to specify a unique XML name and/or namespace for the type.

or even

File or assembly name s5plrkv5.dll, or one of its dependencies, was not found.

After a bit of research I came across this helpful post on the official Amazon.com Web Services discussion board which explains how to fix the issues I was having:

Workaround:

  1. Double click on "Web References" in your VS.NET solution.
  2. Double click on the "WebReference" object and the Object Browser window should open up.
  3. In the Object Browser window’s left pane, double click on the object with the same name as your application. This should expand the list tree. Double click on the .WebReference object and this should expand to a list of objects starting with "AccessoriesAccessory".
  4. In this list of objects, double click on AWSECommerceService. This should open up the source code file that VS.NET generates when it parses the WSDL. Search for "public class CustomerReviews1". You should see the following lines of code.

    [System.Xml.Serialization.XmlTypeAttribute(TypeName="CustomerReviews", Namespace="http://webservices.amazon.com/AWSECommerceService/2004-10-19")]

    public class CustomerReviews1 {
     
  5. Replace the TypeName="CustomerReviews" with TypeName="CustomerReviews1".
  6. Save this file.

 

Dependencies not found issue:

On running your application, Microsoft’s runtime framework will display the following error.

"Server Error in /XXX Application
File or Assembly name yyy.dll, or one of its dependencies, was not found."

(The name of the file (yyy) is not fixed and will vary for every execution run.)

Workaround:

  1. Follow the instructions above to open the AWSECommerceService class generated by VS.NET.
  2. Search for "public string[][] Request;". You should see the following lines of code.

    [System.Xml.Serialization.XmlArrayItemAttribute("BrowseNodeId", typeof(string), IsNullable=false)]
    public string[][] Request;
  3. Modify these lines to

    [System.Xml.Serialization.XmlArrayItemAttribute("BrowseNodeId", IsNullable=false)]
    public string[] Request;
  4. Save this file.

 

Thanks to those tips (I never would have figured it out myself) I was able to get the search tool for my app up and running.

posted @ Tuesday, November 09, 2004 9:26 AM

Print
«July»
SunMonTueWedThuFriSat
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789