简体   繁体   English

使用Asp.net的Amazon Book Search API

[英]Amazon Book Search API using Asp.net

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

http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl Create a proxy using svcutil.exe for above given url and then this is the Method to GetBookByISBN. http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl使用svcutil.exe为上面给定的URL创建代理,然后这是GetBookByISBN的方法。 AmazonBook is my cutom DTO you have to create you own. 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, Reagards,

You can use this library Nager.AmazonProductAdvertising you can install it easy with nuget. 您可以使用此库Nager.AmazonProductAdvertising,您可以使用nuget轻松安装它。 The library also support .NET Standard 2.0 该库还支持.NET Standard 2.0

You can find here a asp.net Website implementation example 你可以在这里找到一个asp.net网站实现示例

PM> Install-Package Nager.AmazonProductAdvertising

Short example: 简短的例子:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM