error CS0030: Cannot convert type 'Simple.Amazon.ECS.ImageSet[]' to 'Simple.Amazon.ECS.ImageSet' in Amazon Web Service
Asked Answered
L

1

8

I Am trying to make a small application which can search a book in amazon by it`s ISBN.

I am following below links :

http://flyingpies.wordpress.com/2009/08/01/17/

http://flyingpies.wordpress.com/2009/08/13/signing-amazon-product-advertising-api-cwcf-part-2/

Search amazon example with new amazon service

And My Code Is :

BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
binding.MaxReceivedMessageSize = int.MaxValue;

AWSECommerceServicePortTypeClient amazonClient = new AWSECommerceServicePortTypeClient(
    binding, new EndpointAddress("https://webservices.amazon.com/onca/soap?Service=AWSECommerceService"));

amazonClient.ChannelFactory.Endpoint.Behaviors.Add(new AmazonSigningEndpointBehavior(AccessKeyId, SecretAccessKey));

ItemLookup lookup = new ItemLookup();
ItemLookupRequest request = new ItemLookupRequest();

request.IdType = ItemLookupRequestIdType.ISBN;
request.ItemId = new[] {"9780297870470"};
request.ResponseGroup = new[] { "OfferSummary" };
request.SearchIndex = "All";
request.IdTypeSpecified = true;

lookup.Request = new ItemLookupRequest[] { request };
lookup.AWSAccessKeyId = AccessKeyId;
lookup.AssociateTag = "wwwyaodaromane-90";
var response = amazonClient.ItemLookup(lookup);

When I try to Send Request I get this exception

There was an error in serializing body of message ItemSearchRequest1: 'Unable to generate a temporary class (result=1).

error CS0030: Cannot convert type 'Simple.Amazon.ECS.ImageSet[]' to 'Simple.Amazon.ECS.ImageSet'

Inner Exception Is :

{"Unable to generate a temporary class (result=1).\r\nerror CS0030: Cannot convert type 'Simple.Amazon.ECS.ImageSet[]' to 'Simple.Amazon.ECS.ImageSet'\r\nerror CS0029: Cannot implicitly convert type 'Simple.Amazon.ECS.ImageSet' to 'Simple.Amazon.ECS.ImageSet[]'\r\n"}

I don`t understand why I'm getting this. What I am doing wrong?

Lydialydian answered 9/9, 2013 at 13:2 Comment(0)
A
14

This is usually a bug in the WCF proxy generation. See here for some details and a workaround.

Taken from comment link:

These are the steps as of January 31, 2012 to fix this issue in Visual Studio for .Net clients:

1) Click the "Show all files" button in the Solution Explorer for the project containing the amazon service reference.

2) Expand the reference and open the AWSECommerceService.wsdl file in the editor

3) On line 584 change the "maxOccurs' to "1".

4) Save the AWSECommerceService.wsdl file

5) Right click Reference.svcmap and click "Run custom tool"

6) Expand Reference.svcmap and open either Reference.cs or Reference.vb

7) Navigate to AmazonAPI.your namespace.Item using the drop down at the top of the window.

8) Navigate to the ImageSets property and confirm that its declaration looks like this:

public ImageSet[] ImageSets {

and NOT like this

public ImageSet[][] ImageSets {

9) Rebuild your project

Armond answered 9/9, 2013 at 13:30 Comment(3)
For anyone else who comes across this problem, the exact fix is detailed here in J. B. Bradshaw's post: forums.aws.amazon.com/thread.jspa?threadID=72429Matronly
Thanks, it worked for me exactly as you said, but now I am facing new errors. So hard to use Amazon APIs...Legumin
I just ran into a similar problem with Fedex api. In VS 2019 the fix is slight different: 1. Double click the .xsd file right under the web service in solution explorer 2. Click "Use the XML editor to view and edit the underlying XML schema file" 3. Fix the proper XML entity by changing maxOccurs="unbounded" to maxOccurs="1" 4. Right click on Reference.map and click Run custom toolEnrico

© 2022 - 2024 — McMap. All rights reserved.