【问题标题】:Amazon Book Search API using Asp.net使用 Asp.net 的亚马逊图书搜索 API
【发布时间】:2011-05-19 03:35:51
【问题描述】:

如何使用亚马逊 API 在 asp.net 中使用 ISBN 号搜索图书?

【问题讨论】:

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


    【解决方案1】:

    http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl 使用 svcutil.exe 为上述给定的 url 创建一个代理 然后这是 GetBookByISBN 的方法。 AmazonBook 是我的自定义 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;
    
    
        }
    

    问候,

    【讨论】:

    • 这是一个 wcf 服务参考?我会对 SOAP 网络服务更感兴趣。
    • 关联标签?我可以看到访问密钥但关联标签?
    • 关联标签是亚马逊用来跟踪用户的东西,从某个亚马逊账户重定向到亚马逊。更多信息可以在forums.aws.amazon.com/thread.jspa?messageID=149729找到。
    • btw 服务在 wsdl 中,您也可以将其用作复古 Web 服务。
    【解决方案2】:

    您可以使用这个库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");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-06
      • 1970-01-01
      • 2011-06-12
      • 1970-01-01
      • 2013-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多