【发布时间】:2011-11-07 19:59:36
【问题描述】:
我正在尝试使用新产品亚马逊 API 在亚马逊上搜索产品。我一直在查看他们的示例代码和其他人的示例,但我没有得到任何结果,并且想知道是否有其他人最近使用过该 API 并且可以提供一些帮助?
using System;
using System.ServiceModel;
using Simple.Amazon.ECS;
namespace Simple {
class Program {
// your Amazon ID's
private const string accessKeyId = "*******************";
private const string secretKey = "************************************";
// the program starts here
static void Main(string[] args) {
// create a WCF Amazon ECS client
BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
binding.MaxReceivedMessageSize = int.MaxValue;
AWSECommerceServicePortTypeClient client = new AWSECommerceServicePortTypeClient(
binding,
new EndpointAddress("https://webservices.amazon.com/onca/soap?Service=AWSECommerceService"));
// add authentication to the ECS client
client.ChannelFactory.Endpoint.Behaviors.Add(new AmazonSigningEndpointBehavior(accessKeyId, secretKey));
// prepare an ItemSearch request
ItemSearchRequest request = new ItemSearchRequest();
request.SearchIndex = "Books";
request.Title = "WCF";
request.ResponseGroup = new string[] { "Small" };
ItemSearch itemSearch = new ItemSearch();
itemSearch.Request = new ItemSearchRequest[] { request };
itemSearch.AWSAccessKeyId = accessKeyId;
// issue the ItemSearch request
ItemSearchResponse response = client.ItemSearch(itemSearch);
// write out the results
foreach (var item in response.Items[0].Item) {
Console.WriteLine(item.ItemAttributes.Title);
}
}
}
}
所有示例/示例在结构上都与此类似,但是当涉及到 foreach 循环时,没有返回任何项目(Null),所以我得到一个空异常错误。
【问题讨论】:
-
response究竟包含什么? -
“对象引用未设置为对象的实例”。当它到达 foreach 循环时。
-
希望我能告诉你出了什么问题。我已经运行了从 [1] 下载的代码,它按预期运行。 [1]flyingpies.wordpress.com/2009/08/01/17
-
是的,我也从那里下载了示例并添加了我的访问密钥和秘密密钥,但它会掉下来,如果你刚刚完成它并且它对你有用,那将非常令人沮丧。跨度>
-
添加 itemSearch.AssociateTag = "";进入代码似乎已经解决了这个问题,我正在取回结果。
标签: c# api soap amazon-web-services amazon