The Amazon Ecommerce Service is a great tool not just to monetize you web site, but also to get relevant content into your site. This content is frequently updated and search engines love this!
As I found when researching listing travel guides on my Thailand Hotels web site, the latest version 4.0 ECS have matured into an easy to use and stable offering. When I started using Amazon Web Services about three years ago, there were still some quirks, especially with Unicode encoding (more on that in Part 2).
A good starting point is downloading the AmazonECS.Net library and demo code created by Dominic Bégin. You can then poke around the code and see the objects returned from the web services, and how to handle them in your code.
One little thing that bothered me was that the same code was used for each Amazon country site/locale. The web service proxies created by VS.NET 2005 are all in different namespaces, so it’s impossible or at least very cumbersome to instantiate or subclass to the different locale implementations.
However, since the code is identical for all locales/end points, here’s a workaround:
In your client code, just instantiate any search request object, for example here we use the US version:
| Matizha.AmazonECSNet.US.SearchRequest rq = new Matizha.AmazonECSNet.US.SearchRequest(); |
Then, set the Url property of the proxy class like this (presuming you have a this.Locale string variable):
| if (this.Locale == “de“) |
| { |
| rq.amazonService.Url = http://soap.amazon.de/onca/soap?Service=AWSECommerceService; |
| } |
Or use a switch statement:
| switch (this.Locale) |
| { |
| case “us“: |
| rq.amazonService.Url = “http://soap.amazon.com/onca/soap?Service=AWSECommerceService“; |
| break; |
| case “fr“: |
| rq.amazonService.Url = “http://soap.amazon.fr/onca/soap?Service=AWSECommerceService“; |
| break; |
| case “de“: |
| rq.amazonService.Url = “http://soap.amazon.de/onca/soap?Service=AWSECommerceService“; |
| break; |
| case “uk“: |
| rq.amazonService.Url = “http://soap.amazon.co.uk/onca/soap?Service=AWSECommerceService“; |
| break; |
| case “ca“: |
| rq.amazonService.Url = “http://soap.amazon.ca/onca/soap?Service=AWSECommerceService“; |
| break; |
| case “jp“: |
| rq.amazonService.Url = “http://soap.amazon.co.jp/onca/soap?Service=AWSECommerceService“; |
| break; |
| default: |
| rq.amazonService.Url = “http://soap.amazon.com/onca/soap?Service=AWSECommerceService“; |
| break; |
| } |
While the subscription id/AWS AccessKeyId can be the same for every locale, you have to sign up and get an associate tag for every country site. So it’s probably better to look up the strings above and the respective associate tag from a database or XML document.
Recent Comments