2010-12-02 16 views

Respuesta

2

http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl Crear una svcutil.exe usando proxy para URL anterior dada y entonces este es el método para GetBookByISBN. AmazonBook es mi DTO cutom, tienes que crear tu propio.

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

esto es una referencia de servicio WCF? estaría más interesado en el servicio web SOAP. –

+0

¿Etiqueta asociada? Puedo ver una clave de acceso pero asociar etiqueta? –

+0

Associate Tag es algo que Amazon usó para rastrear a un usuario y se lo redireccionó a Amazon desde cierta cuenta de Amazon .. se puede encontrar más información en https://forums.aws.amazon.com/thread.jspa?messageID=149729 –

0

Puede utilizar esta biblioteca Nager.AmazonProductAdvertising puede instalar fácilmente con Nuget. La biblioteca también soporta .NET Standard 2.0

Usted puede encontrar aquí un ejemplo asp.net Website aplicación

PM> Install-Package Nager.AmazonProductAdvertising 

ejemplo corto:

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