2010-12-02 15 views

答えて

2

http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl 上記の与えられたURLのためにsvcutil.exeを使用してプロキシを作成してください。これは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、

+0

これは、WCFサービス参照のですか? SOAP Webサービスにもっと興味があります。 –

+0

タグを関連付けますか?私はアクセスキーを見ることができますが、タグを関連付けますか? –

+0

アソシエイトタグはAmazonを特定のAmazonアカウントからAmazonにリダイレクトするためにAmazonが使用するものです。詳細はhttps://forums.aws.amazon.com/thread.jspa?messageID=149729 –

0

あなたはnugetと、それは簡単にインストールすることができますNager.AmazonProductAdvertisingこのライブラリを使用することができます。ライブラリはまた、あなたが

PM> Install-Package Nager.AmazonProductAdvertising 

に、ここで簡単な例をasp.net Website実装例を見つけることができます.NET標準2.0

をサポートしています。

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"); 
関連する問題