c# - 错误 CS0030 : Cannot convert type 'Simple.Amazon.ECS.ImageSet[]' to 'Simple.Amazon.ECS.ImageSet' in Amazon Web Service

标签 c# .net wcf amazon amazon-product-api

我正在尝试制作一个小型应用程序,它可以通过 ISBN 在亚马逊上搜索一本书。 我是 Amazon Web Service 的新手。

我正在关注以下链接:

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

我的代码是:

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);

当我尝试发送请求时出现异常

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'

内部异常是:

{"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"}

我不明白为什么我会得到这个。我做错了什么?

最佳答案

这通常是 WCF 代理生成中的错误。 See here了解一些细节和解决方法。

取自comment link :

这些是截至 2012 年 1 月 31 日在 Visual Studio for .Net 客户端中修复此问题的步骤:

1) 在包含亚马逊服务引用的项目的解决方案资源管理器中单击“显示所有文件”按钮。

2) 展开引用并在编辑器中打开 AWSECommerceService.wsdl 文件

3) 在第 584 行,将“maxOccurs”更改为“1”。

4) 保存 AWSECommerceService.wsdl 文件

5) 右击Reference.svcmap并点击“运行自定义工具”

6) 展开 Reference.svcmap 并打开 Reference.cs 或 Reference.vb

7) 使用窗口顶部的下拉菜单导航到 AmazonAPI.your namespace.Item。

8) 导航到 ImageSets 属性并确认其声明如下所示:

public ImageSet[] ImageSets {

不是这样的

public ImageSet[][] ImageSets {

9) 重建你的项目

关于c# - 错误 CS0030 : Cannot convert type 'Simple.Amazon.ECS.ImageSet[]' to 'Simple.Amazon.ECS.ImageSet' in Amazon Web Service,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18698856/

相关文章:

c# - 如何将枚举设置为空

c# - yield 和 Parallel.ForEach 的奇怪行为

c# - Json.Net 可以处理 List<object> 吗?

c# - 如何从 Active Directory 检索用户的登录名?

c# - 创建一个确认框 c#

.net - 缩小编码为 Base64 的 float 据字节

.net - openxml 选项完全采用文本格式吗?

c# - 如何在 WCF 服务中将接口(interface)作为参数传递?

wcf - 我什么时候应该在 WCF 中使用数据契约(Contract)以及什么时候使用消息契约(Contract)

c# - MonoTouch WCF Service Reference.cs 错误