• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2320
  • Last Modified:

How to implement amazon api service?

I want to imlement amazon api web service to my application. I have implemente it but its gives error. The error is 'The request must contain the parameter Signature'. How can I solve it?
Thanks.
0
avacaralife
Asked:
avacaralife
  • 5
  • 3
1 Solution
 
Vel EousResearch & Development ManagerCommented:
Take a look at the following two web pages:

1) http://developer.amazonwebservices.com/connect/ann.jspa?annID=483

Amazon documentation on the enforcement of signed API requests including developers guide and sample source code


2) http://richardcummings.info/AWS-Signature-Parameter-Convert.php

"AWS Signature Parameter Convert Utility" provided by someone who had a similar issue to yourself.

Hope this helps.
0
 
avacaralifeAuthor Commented:
Thanks Tchuki.

Right now I am implementing my web application in .net 2008. I have use the Amazon web service. the web service ULR is : http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl 

When I try to get Item details using ItemLookupRequest, It gives error.

The error is : "The request must contain the parameter Signature"

Show below is my code :


    protected void Button1_Click(object sender, EventArgs e)
    {
       //// Amazon.EC2.AmazonEC2Client c = new Amazon.EC2.AmazonEC2Client("", "");

        //have we this in the cache already?  
        com.amazon.webservices.ItemLookupResponse response;

        if (Cache[TextBox1.Text] == null)
        {
            com.amazon.webservices.AWSECommerceService aws = new com.amazon.webservices.AWSECommerceService();
            com.amazon.webservices.ItemLookupRequest request = new com.amazon.webservices.ItemLookupRequest();
            string lStrCertPath;
            //lStrCertPath=
            System.Security.Cryptography.X509Certificates.X509Certificate X509Certificate = new System.Security.Cryptography.X509Certificates.X509Certificate(Server.MapPath("") + "\\cert-364S3JDEKPEOT6VYWBFLVZPECE6QOVMT.pem");
            aws.ClientCertificates.Add(X509Certificate);

            request.SearchIndex = "Books";

            //request. = "title:" + TextBox1.Text;  
            request.ResponseGroup = new string[] { "Small" };
            //request.SearchIndex = "salesrank";

            com.amazon.webservices.ItemLookupRequest[] requests = new com.amazon.webservices.ItemLookupRequest[] { request };

            com.amazon.webservices.ItemLookup itemSearch = new com.amazon.webservices.ItemLookup();
            itemSearch.SubscriptionId = "6MmIULpFVdbxHgh7udwhcJyVOxhkSQpUeqp0SY/N";
            // itemSearch.AssociateTag = "AKIAIJP5BCYL7WMRMD5A";
            //  itemSearch.SubscriptionId = "AKIAJPMM324XXNMQ7AXQ";
            //itemSearch.SubscriptionId = "AKIAJPMM324XXNMQ7AXQ";
            itemSearch.AWSAccessKeyId = "AKIAIJP5BCYL7WMRMD5A";
            // itemSearch.Validate = "false";

            // itemSearch.AWSAccessKeyId = "AKIAJPMM324XXNMQ7AXQ";  
            itemSearch.Request = requests;
            //.ClientCertificates.Add(X509Certificate.CreateFromCertFile(X509CertFile));
            request.Condition = com.amazon.webservices.Condition.All;

            response = aws.ItemLookup(itemSearch);
            Cache.Insert(TextBox1.Text, response, null,
                DateTime.Now.AddHours(24), TimeSpan.Zero);
        }
        else
        {
            response = (com.amazon.webservices.ItemLookupResponse)Cache[TextBox1.Text];
        }
        com.amazon.webservices.Items info = response.Items[0];
        com.amazon.webservices.Item[] items = info.Item;
        Label1.Text = "";
        for (int i = 0; i < items.Length; i++)
        {
            com.amazon.webservices.Item item = items[i];
            Label1.Text += "Book Title: " + item.ItemAttributes.Title + "<br />";
        }
        GridView1.DataSource = AmazonToDataSet("title: " + TextBox1.Text);
        GridView1.DataBind();
       }
   
    public DataSet AmazonToDataSet(string PowerSearchString)
    {

        DataSet ds;

        //have we this in the cache already?  
        if (Cache[PowerSearchString] == null)
        {
            //create our query  
            com.amazon.webservices.ItemLookupResponse response =
                grabAmazonSearch(PowerSearchString);

            //Construct the dataset to store the results  
            ds = new DataSet();
            ds.Tables.Add();

            ds.Tables[0].Columns.Add("ProductName");
            ds.Tables[0].Columns.Add("AuthorName");
            ds.Tables[0].Columns.Add("Price");
            ds.Tables[0].Columns.Add("URL");

            com.amazon.webservices.Items info = response.Items[0];
            com.amazon.webservices.Item[] items = info.Item;
            DataRow dr;

            //iterate the results adding new rows with  
            //the values from the search result item.  

            for (int i = 0; i < items.Length; i++)
            {
                com.amazon.webservices.Item item = items[i];
                dr = ds.Tables[0].NewRow();
                dr["ProductName"] = item.ItemAttributes.Title;
                dr["AuthorName"] = item.ItemAttributes.Author[0];
                dr["Price"] = item.ItemAttributes.ListPrice;
                dr["URL"] = item.DetailPageURL;
                ds.Tables[0].Rows.Add(dr);
            }

            //add the dataset to the cache  
            Cache.Insert(PowerSearchString, ds, null,
                DateTime.Now.AddHours(24), TimeSpan.Zero);

        }
        else
        {
            ds = (DataSet)Cache[PowerSearchString];
        }
        //return the dataset  
        return ds;
    }


    private com.amazon.webservices.ItemLookupResponse grabAmazonSearch(string PowerSearchString)
    {
        com.amazon.webservices.ItemLookupResponse response;
        com.amazon.webservices.AWSECommerceService aws = new com.amazon.webservices.AWSECommerceService();
        com.amazon.webservices.ItemLookupRequest request = new com.amazon.webservices.ItemLookupRequest();

        request.SearchIndex = "Books";

        //request.Power = PowerSearchString;
        request.ResponseGroup = new string[] { "Small" };
        //request.Sort = "salesrank";

        com.amazon.webservices.ItemLookupRequest[] requests = new com.amazon.webservices.ItemLookupRequest[] { request };

        com.amazon.webservices.ItemLookup itemSearch = new com.amazon.webservices.ItemLookup();
        //itemSearch.AssociateTag = "myassociatetag-20";
        itemSearch.SubscriptionId = "AKIAIJP5BCYL7WMRMD5A";
//        itemSearch.AWSAccessKeyId = "AKIAJPMM324XXNMQ7AXQ";  
        itemSearch.Request = requests;

        response = aws.ItemLookup(itemSearch);

        return response;
    }


Give me solution As early as possible.

Thanks in advanse.
0
 
Vel EousResearch & Development ManagerCommented:
I've not dealt with AWS API myself which is why I provided the two links.

Perhaps you could provide more information such as which line is generating the error?  You can step through your code using F11 in Visual Studio and when it hits the offending line will automatically stop.

However from the reading I have done using the links I provided for YOU to look through, it can be determine that you require a HMAC-SHA signature concatinated to your API URL.

Take a look at these pages for further info:

// Product Advertising API documentation
http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/index.html?RequestAuthenticationArticle.html

// Signed request generator
http://associates-amazon.s3.amazonaws.com/signed-requests/helper/index.html

0
Protect Your Employees from Wi-Fi Threats

As Wi-Fi growth and popularity continues to climb, not everyone understands the risks that come with connecting to public Wi-Fi or even offering Wi-Fi to employees, visitors and guests. Download the resource kit to make sure your safe wherever business takes you!

 
avacaralifeAuthor Commented:
Yes here is the screen shoot of error I have attached. look over it.
Error.png
0
 
Vel EousResearch & Development ManagerCommented:
Does your itemSearch object have a property or method called Signature?


itemSearch.Signature = "";

Open in new window

0
 
avacaralifeAuthor Commented:
No there is no signature property.
0
 
Vel EousResearch & Development ManagerCommented:
Basically that error message is informing you that your SOAP message does not have a value for a required parameter (web services can implemenet parameters however they can be specified as either IsRequired = true | false).

I did a further google search and turns out the parameter is part of the SOAP header rather than the SOAP body, take a look at the following web page which has been created by someone who has had the same issue or one very similar to yours and provides information regarding a resolution.

http://flyingpies.wordpress.com/2009/08/01/17/


This following page might also be of use to you.

http://apisigning.com/
0
 
Vel EousResearch & Development ManagerCommented:
I would be curious to know just what the resolution was as I feel the information I provided was valid in relation to the question and subsequent information provided.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Protect Your Employees from Wi-Fi Threats

As Wi-Fi growth and popularity continues to climb, not everyone understands the risks that come with connecting to public Wi-Fi or even offering Wi-Fi to employees, visitors and guests. Download the resource kit to make sure your safe wherever business takes you!

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now