If you have had the misfortune of trying to use the new
Amazon Affiliate Amazon Product API/WSDL based on
their .NET C# examples, you will of course have found that nothing
has been updated and some of the properties previously used
(Especially the one to sign the request) 'SEEM' to have been
removed.
You'll also find that (as of writing this) the new WSDL they
want you to use, actually doesn't work and has a bug which will
return something like the following error!! And they have known
about it for months…
System.ServiceModel.CommunicationException: There was an error in serializing body of message ItemSearchRequest1: 'Unable to generate a temporary class (result=1).
error CS0030: Cannot convert type 'AmazonService.AWSECommerceServiceAPI.ImageSet[]' to 'AmazonService.AWSECommerceServiceAPI.ImageSet'
error CS0029: Cannot implicitly convert type 'AmazonService.AWSECommerceServiceAPI.ImageSet' to 'AmazonService.AWSECommerceServiceAPI.ImageSet[]'
This post will get round both of the above, firstly we'll
address the WSDL fix to the above error.
WSDL Fix
You'll need to add the new WSDL file and then browse to your
'Web Reference' folder on your file system and
open up your 'AWSECommerceService.wsdl' file in
Notepad++ or similar
Then search for the bolded line below
<xs:element name="ImageSets" minOccurs="0"
maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element ref="tns:ImageSet" minOccurs="0"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
And change it to:
<xs:element name="ImageSets" minOccurs="0"
maxOccurs="1">
Now you need to open up your 'Reference.cs'
file in the same folder and replace all references to (Notice
the double brackets!!)
ItemSearch[][]
With
ItemSearch[]
Save both and build your project and you can now actually use
it.
Microsoft.Web.Services3 Issue
If like me you have always been using the
Microsoft.Web.Services3 along with the AmazonHmacAssertion class,
and now in your product look up code you have found that
AWSECommerceService.Destination & AWSECommerceService.SetPolicy
are now missing then this fix is for you. Again you will need
to open up your 'Reference.cs' file in the same
folder and replace all references to
System.Web.Services.Protocols.SoapHttpClientProtocol
To
Microsoft.Web.Services3.WebServicesClientProtocol
Save the file and rebuild… And all back to normal!
The problem being SetPolicy() and Destination() belong to a
class inside WSE 3.0 Web services, which is what the Amazon samples
use. When you generate (OR UPDATE) a Web Reference in VS without
WSE 3.0, it defaults the "AWSECommerceService" to inherit from:
System.Web.Services.Protocols.SoapHttpProtocol.
This class doesn't have a "SetPolicy" method or "Destination"
REMEMBER: If you update/regenerate your web reference you'll
have to change all the above again!