2010-12-02 10 views

Antwort

2

http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl Proxy verwenden svcutil.exe URL oben angegebenen erstellen für und dann ist dies die Methode zu GetBookByISBN. AmazonBook ist mein Cutom DTO, das du dir selbst erstellen musst.

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

dies ist eine WCF-Dienst Referenz? Ich wäre mehr interessiert an SOAP Webservice. –

+0

Assoziierte Marke? Ich kann einen Zugriffsschlüssel sehen, aber ein Tag zuordnen? –

+0

Associate Tag ist etwas, das Amazon verwendet, um zu verfolgen, dass ein Benutzer von einem bestimmten Amazon-Konto zu Amazon umgeleitet wird. Weitere Informationen finden Sie unter https://forums.aws.amazon.com/thread.jspa?messageID=149729 –

0

können Sie diese Bibliothek verwenden Nager.AmazonProductAdvertising Sie installieren können, es mit nuget einfach. Die Bibliothek unterstützt auch .NET Standard 2.0

Sie können

PM> Install-Package Nager.AmazonProductAdvertising 

Kurz Beispiel hier ein asp.net Website Implementierungsbeispiel finden:

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