- Category: ASP.Net
- Published on Saturday, 16 April 2011 03:12
- Written by Shabdar
- Hits: 13597
As many of you know, Starting August 15, 2009, all Amazon API requests must be authenticated using signatures.There is a whole bunch of documentation on Amazon website that describes how to authenticate requests. Visit following URL for more information.
But as a newbie to Amazon APIs it was lot more difficult for me to build a working sample in ASP.Net and C#. After hours of search, I came across following article that helped me build my first successful sample. This article provided me a helper class in VB that can be used to generate a signed URL. I had to convert it in C#.
Download my sample code from above link and open it with Visual Studio 2005 or 2008 as a website. I have used .Net Framework 2.0 for this sample. But it should work fine with version 3.5 as well.
Most of the sample code is self explanatory. Comments are written inline with source code which should help you get started.
Following are key notes for this sample to work.
Go to Default.aspx.cs file and change your access key and secret key in following lines
If you are behind corporate firewall or proxy, you may need to authenticate HTTP requests. For that go to Web.config file and enter your windows user name and password in app.Settings.
Source Code Explanation
Most important part in this sample are following lines which are used to generate signed URL.
As you can see requestParams is an array which holds all the parameters to be passed along with request url.
Once you have signed URL ready, you can use WebRequest class to get response from Amazon web service.
As you can see in above code, we get response in XML format which is then read into a Dataset. Dataset stores it as Tables.
Note that I am not referencing Amazon Web Service in this project. It could have been lot more easier to just use web methods to get Items. But unfotunately I could not find any way of signing a request with webservice.
Once we have returned data into dataset we can just bind these tables with Grid View or whatever way you want to use it.
In my sample I have just implemented search service from amazon. You can also implement Item Lookup in similar way. You just need to change request parameters in my sample. Feel free to modify it as you desire.