Amazon Web Service Secure Request

by Viper 15. June 2009 13:41

Some time back I wrote a post on C# API for Amazon Product Advertising Web Service. If you are one of amazon associates who is using their web service to advertise their products to earn some money, then you must be getting emails with following message from Amazon.com.

We wanted to remind you that all Product Advertising API developers will be required to authenticate all calls to the Product Advertising API by August 15, 2009. We noticed that requests with your AWS Access Key ID are not being signed and, while you have more than 60 days until the date on which authentication is required, we are, as a courtesy, sending you this email to remind you of the new authentication requirement. Please remember that calls to the Product Advertising API that are not signed will not be processed after August 15, 2009.

There is nothing to worry about this. It is a very simple change that you will need to make on your end. Amazon has given two options to digitally sign the requests. Either encrypt all requests with HMAC-SHA encryption or use X509Certificate. If you don't have X509Certificate, don't worry about it. Amazon.com is creating one for you if you ask it to. I found this option to use X509Certificate to be the easiest to comply with Amazon.com policy. Here are the steps you will need to use.

  • Login into your AWS account.
  • Click on Access Identifiers link on Your Account page.
  • At the end of the page you will find section for X509.Certificate. Click on Create New option to create your certificate.
  • Make sure that you follow the instructions and save the private key and certificate file as the process asks you to.

Now time to make code change. It is simple. Just add one line to your implementation and you are all set.


m_obAmazonService.ClientCertificates.Add(X509Certificate.CreateFromCertFile(X509CertFile));

X509CertFile is full path to where this file is stored. If you are using the API in web application, make sure you specify fully qualified path and your application has read permissions on this file as well. You can this in action here - Winazon.Net

Views: 17224

Tags: ,

.Net | ECommerce

Connect to Amazon.com web service using WCF

by Viper 3. February 2009 08:39

In my previous post WCF Error I discussed adding app.config to your application to get Amazon.com web service client to work. I also mentioned in that post that you can provide Binding and EndPoint parameters programatically to send search request to Amazon.com web service. Here is the sample code that demonstrates how you can do that.


using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Channels;
using AmazonClient.AmazonData;
namespace AmazonClient
{
  class Program
  {
    static void Main(string[] args)
    {
       System.ServiceModel.BasicHttpBinding httpBinding = new BasicHttpBinding();
       httpBinding.Name = "AWSECommerceServiceBinding";
       BasicHttpSecurity security = httpBinding.Security;
       security.Mode = BasicHttpSecurityMode.None;
       EndpointAddress addr = 
         new EndpointAddress("http://soap.amazon.com/onca/soap?Service=AWSECommerceService");
       AWSECommerceServicePortTypeClient client = 
        new AWSECommerceServicePortTypeClient(httpBinding,  addr);
            
       try
       {
         ItemSearch srch = new ItemSearch();
         srch.AssociateTag = "xxxxxxx";
         srch.AWSAccessKeyId = "xxxxxx";
         ItemSearchRequest req = new ItemSearchRequest();
         req.Keywords = "silverlight";
         req.SearchIndex = "Books";
         srch.Request = new ItemSearchRequest[1]{req};
         ItemSearchResponse resp = client.ItemSearch(srch);
         if (null != resp)
         {
           Console.WriteLine("It works!");
         }
       }
       catch(Exception ex)
       {
         Console.WriteLine(ex.Message);
       }
    }
   }
}

Views: 5142

Tags:

WCF | ECommerce

Powered by BlogEngine.NET 1.5.1.7
Theme by Naveen Kohli