Amazon Product Advertising API SOAP Namespace Changes

Posted by Rick Strahl on West-Wind See other posts from West-Wind or by Rick Strahl
Published on Thu, 03 May 2012 11:36:08 GMT Indexed on 2012/05/30 16:42 UTC
Read the original article Hit count: 657

Filed under:
|

About two months ago (twowards the end of February 2012 I think) Amazon decided to change the namespace of the Product Advertising API. The error that would come up was:

<ItemSearchResponse > was not expected.

If you've used the Amazon Product Advertising API you probably know that Amazon has made it a habit to break the services every few years or so and I guess last month was about the time for another one.

Basically the service namespace of the document has been changed and responses from the service just failed outright even though the rest of the schema looks fine.

Now I looked around for a while trying to find a recent update to the Product Advertising API - something semi-official looking but everything is dated around 2009. Really??? And it's not just .NET - the newest thing on the sample/APIs is dated early 2011 and a handful of 2010 samples. There are newer full APIs for the 'cloud' offerings, but the Product Advertising API apparently isn't part of that.

After searching for quite a bit trying to trace this down myself and trying some of the newer samples (which also failed) I found an obscure forum post that describes the solution of getting past the namespace issue.

FWIW, I've been using an old version of the Product Advertising API using the old Microsoft WSE3 services (pre-WCF), which provides some of the WS* security features required by the Amazon service. The fix for this code is to explicitly override the namespace declaration on each of the imported service method signatures.

The old service namespace (at least on my build) was:

http://webservices.amazon.com/AWSECommerceService/2009-03-31

and it should be changed to:

http://webservices.amazon.com/AWSECommerceService/2011-08-01

Change it on the class header:

[Microsoft.Web.Services3.Messaging.SoapService("http://webservices.amazon.com/AWSECommerceService/2011-08-01")]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(Property[]))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(BrowseNode[]))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(TransactionItem[]))]
public partial class AWSECommerceService : Microsoft.Web.Services3.Messaging.SoapClient {

and on all method signatures:

[Microsoft.Web.Services3.Messaging.SoapMethodAttribute("http://soap.amazon.com/ItemSearch")]
[return: System.Xml.Serialization.XmlElementAttribute("ItemSearchResponse", 
Namespace="http://webservices.amazon.com/AWSECommerceService/2011-08-01")] public ItemSearchResponse ItemSearch(ItemSearch ItemSearch1) { Microsoft.Web.Services3.SoapEnvelope results = base.SendRequestResponse("ItemSearch", ItemSearch1); return ((ItemSearchResponse)(results.GetBodyObject(typeof(ItemSearchResponse), this.SoapServiceAttribute.TargetNamespace))); }

It's easy to do with a Search and Replace on the above strings.

Amazon Services

<rant>

FWIW, I've not been impressed by Amazon's service offerings. While the services work well, their documentation and tool support is absolutely horrendous. I was recently working with a customer on an old AWS application and their old API had been completely removed with a new API that wasn't even a close match. One old API call resulted in requiring three different APIs to perform the same functionality. We had to re-write the entire piece from scratch essentially. The documentation was downright wrong, and incomplete and so scattered it was next to impossible to follow. The examples weren't examples at all - they're mockups of real service calls with fake data that didn't even provide everything that was required to make same service calls work. Additionally there appears to be just about no public support from Amazon, only peer support which is sparse at best - and getting a hold of somebody at Amazon, even for pay seems to be mythical task. It's a terrible business model they have going. I can't see why anybody would put themselves through this sort of customer and development experience.

Sad really, but an experience we see more and more these days. Nobody puts in the time to document anything anymore, leaving it to devs to figure this stuff out over and over again…

</rant>

© Rick Strahl, West Wind Technologies, 2005-2012
Posted in CSharp  Web Services  

© West-Wind or respective owner

Related posts about CSharp

Related posts about Web Services