加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

使用Asp.net的Amazon Book Search API

发布时间:2020-12-16 03:20:10 所属栏目:asp.Net 来源:网络整理
导读:如何使用amazon API在asp.net上使用ISBN号搜索图书? 解决方法 http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl 使用svcutil.exe为上面给出的URL创建代理 然后这是GetBookByISBN的方法. AmazonBook是我必须创建自己的cutom DTO
如何使用amazon API在asp.net上使用ISBN号搜索图书?

解决方法

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,

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读