使用Asp.net的Amazon Book Search API

时间:2010-12-02 13:44:21

标签: asp.net json asp.net-ajax amazon-web-services

如何使用amazon API在asp.net上使用ISBN编号搜索图书?

2 个答案:

答案 0 :(得分:2)

http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl 使用svcutil.exe为上面给出的URL创建代理 然后这是GetBookByISBN的方法。 AmazonBook是我必须创建自己的cutom DTO。

public static AmazonBook GetBookByISBN(string ISBN)
    {
        WebConfigHelper wch = new WebConfigHelper("AWSSettings");
        AmazonBook book = null;
        string AWSAccessKeyId = wch["AccessKey"];
        string AssociateTag = wch["AssociateTag"];
        string AWSSecKey = wch["SecretKey"];

        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(AWSAccessKeyId, AWSSecKey));


        ItemSearchRequest request = new ItemSearchRequest();
        request.SearchIndex = "Books";
        request.Power = "ISBN:" + ISBN.Trim();
        request.ResponseGroup = new string[] { "Large" };
        request.Sort = "salesrank";

        ItemSearchRequest[] requests = new ItemSearchRequest[] { request };

        ItemSearch itemSearch = new ItemSearch();
        itemSearch.AWSAccessKeyId = AWSAccessKeyId;
        itemSearch.AssociateTag = AssociateTag;
        itemSearch.Request = requests;


        try
        {
            ItemSearchResponse response = client.ItemSearch(itemSearch);
            Items info = response.Items[0];
            if (info.Item != null)
            {
                Item[] items = info.Item;
                if (items.Length == 1)
                {
                    book = new AmazonBook(items[0]);
                }
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return book;


    }

Reagards,

答案 1 :(得分:0)

您可以使用此库Nager.AmazonProductAdvertising,您可以使用nuget轻松安装它。该库还支持.NET Standard 2.0

您可以在此处找到asp.net Website实施示例

PM> Install-Package Nager.AmazonProductAdvertising

简短的例子:

var authentication = new AmazonAuthentication();
authentication.AccessKey = "accesskey";
authentication.SecretKey = "secretkey";

var wrapper = new AmazonWrapper(authentication, AmazonEndpoint.US);
//The Lord of the Rings
var result = wrapper.Lookup("978-0261102385");