如何更好地请求亚马逊产品广告API Web服务?

我在我的MVC项目中使用亚马逊产品广告API Web服务。 我创建了简单的C#控制台项目来测试域类。 默认情况下,Amazon Product Advertising Api Web服务请求每页不能返回超过10个项目,但我需要在我的网页中显示更多10个项目。

为此我创建了额外的逻辑

namespace AmazonProductAdvertisingAPI.Console
{
    class Program
    {
        private const string accessKeyId = "####";
        private const string secretKey = "####";

        static void Main(string[] args)
        {
            BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
            binding.MaxReceivedMessageSize = int.MaxValue;
            // create a WCF Amazon ECS client
            AWSECommerceServicePortTypeClient client = new AWSECommerceServicePortTypeClient(
                //new BasicHttpBinding(BasicHttpSecurityMode.Transport),
                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

            string searchIndex = "Books";
            string title = "Bible";
            string[] responseGroup = new string[] { "Small", "ItemAttributes" };

            ItemSearchRequest firstRequest = new ItemSearchRequest();
            firstRequest.SearchIndex = searchIndex;
            firstRequest.Title = title;
            firstRequest.ResponseGroup = responseGroup;
            firstRequest.ItemPage = "1";
            ItemSearch itemSearch = new ItemSearch();
            itemSearch.Request = new ItemSearchRequest[] { firstRequest };
            itemSearch.AWSAccessKeyId = accessKeyId;
            itemSearch.AssociateTag = "http://affiliate-program.amazon.com/";
            ItemSearchResponse firstResponse = client.ItemSearch(itemSearch);
            foreach (var item in firstResponse.Items[0].Item)
            {
                System.Console.WriteLine(item.ItemAttributes.Title);
            }
            int totalPages = Convert.ToInt32(firstResponse.Items[0].TotalPages);
            if (totalPages > 1)
            {
                for (int i = 2; i < totalPages; i++)
                {
                    AWSECommerceServicePortTypeClient newclient = new AWSECommerceServicePortTypeClient(
                //new BasicHttpBinding(BasicHttpSecurityMode.Transport),
                binding,
                new EndpointAddress("https://webservices.amazon.com/onca/soap?Service=AWSECommerceService"));
                    newclient.ChannelFactory.Endpoint.Behaviors.Add(new AmazonSigningEndpointBehavior(accessKeyId, secretKey));
                    ItemSearchRequest repeatedRequest = new ItemSearchRequest()
                    {
                        SearchIndex = searchIndex,
                        Title = title,
                        ResponseGroup = responseGroup,
                        ItemPage = Convert.ToString(i)
                    };
                    ItemSearch rItemSearch = new ItemSearch();
                    rItemSearch.Request = new ItemSearchRequest[] { repeatedRequest };
                    rItemSearch.AWSAccessKeyId = accessKeyId;
                    rItemSearch.AssociateTag = "http://affiliate-program.amazon.com/";

                    ItemSearchResponse repeatedResponse = newclient.ItemSearch(rItemSearch);
                    foreach (var item in repeatedResponse.Items[0].Item)
                    {
                        System.Console.WriteLine(item.ItemAttributes.Title);
                    }
                }
            }
        }
    }
}

回报我:

mscorlib.dll中发生未处理的类型为“System.ServiceModel.ServerTooBusyException”的异常其他信息:位于https://webservices.amazon.com/onca/soap?Service=AWSECommerceService的HTTP服务不可用。 这可能是因为服务太忙或者因为没有端点被发现在指定的地址处侦听。 请确保地址正确,然后再次尝试访问该服务。

有人可以帮助它并提供一些建议吗?

链接地址: http://www.djcxy.com/p/39029.html

上一篇: How better request Amazon Product Advertising API Web service?

下一篇: Amazon Product Advertising API Signature