How better request Amazon Product Advertising API Web service?

I use Amazon Product Advertising API Web service in my MVC project. I created simple C# Console project to test Domain Classes. By default Amazon Product Advertising Api Web service request can't return more than 10 item per page, but I need display more that 10 items in my web page.

For it I create additional logic

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

Return me:

An unhandled exception of type 'System.ServiceModel.ServerTooBusyException' occurred in mscorlib.dll Additional information: The HTTP service located at https://webservices.amazon.com/onca/soap?Service=AWSECommerceService is unavailable. This could be because the service is too busy or because no endpoint was found listening at the specified address. Please ensure that the address is correct and try accessing the service again later.

Could somebody help with it and provide some advice?

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

上一篇: 亚马逊API签名

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