How can amazon API be used to search a book using an ISBN number with asp.net?
http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl Create a proxy using svcutil.exe for above given url and then this is the Method to GetBookByISBN. AmazonBook is my cutom DTO you have to create you own.
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,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With