public partial class _Default : System.Web.UI.Page { //Set your Access Key and Secret Key in following variables. private const string MY_AWS_ACCESS_KEY_ID = "my access key"; private const string MY_AWS_SECRET_KEY = "my secret key"; private const string DESTINATION = "ecs.amazonaws.com"; protected void Page_Load(object sender, EventArgs e) { } protected void btnSearch_Click(object sender, EventArgs e) { //Use SignedRequesthelper class to generate signed request. SignedRequestHelper helper = new SignedRequestHelper(MY_AWS_ACCESS_KEY_ID, MY_AWS_SECRET_KEY, DESTINATION); IDictionary<string, string> requestParams = new Dictionary<string, String>(); requestParams["Service"] = "AWSECommerceService"; //Leave following line commented if you want to use latest version of Amazon API. You can uncomment this line to use a specific version. requestParams["Version"] = "2009-03-31"; //requestParams["Operation"] = "ItemLookup"; requestParams["Operation"] = "ItemSearch"; requestParams["SearchIndex"] = selectCategories.Value; requestParams["Keywords"] = txtSearch.Text; //Get signed URL in a variable string requestUrl = helper.Sign(requestParams); //Get response from signed request DataSet DS = GetData(requestUrl); if (DS != null) { //Bind ItemAttributes table returned in dataset. This will give you product details. gridViewAttributes.DataSource = DS.Tables["ItemAttributes"]; gridViewAttributes.DataBind(); //Bind Item table returned in dataset. This will give you product link page. gridViewItem.DataSource = DS.Tables["Item"]; gridViewItem.DataBind(); lblError.Text = ""; //You can set debug point here and inspect content of Datased(DS). //it has few more tables that you might be interested in. } } DataSet GetData(string signedurl) { try { //Create a request object using signed URL. WebRequest request = HttpWebRequest.Create(signedurl); //Get response in a stream //WebRequest request = HttpWebRequest.Create(url); //WebResponse response = request.GetResponse(); Stream responseStream = request.GetResponse().GetResponseStream(); // Stream responses = request.GetResponse().GetResponseStream(); DataSet DS = new DataSet(); //Read returned resonpse stream into a dataset. //Note: You can also use XMLDocument element here to read response. DS.ReadXml(responseStream); responseStream.Close(); return DS; } catch (Exception e) { //If there is an error capture it. //If you get an error, it could be either because of invalid keyword or you provided wrong access key. lblError.Text = e.Message; Response.Write("Caught Exception: " + e.Message); Response.Write("Stack Trace: " + e.StackTrace); } return null; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)