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);
       }
    }
   }
}

Give your advice to big bosses and make money

Views: 6071

Tags:

WCF | ECommerce

Comments

7/19/2009 11:11:40 PM #

sulumits retsambew

great coding, work very well ..thanks

sulumits retsambew United States

9/10/2009 3:58:27 AM #

eve online guide

I admire what you have done here. I like the part where you say you are doing this to give back but I would assume by all the comments that this is working for you as well.

eve online guide United States

10/14/2009 12:24:54 PM #

kfc coupons

Thank you for the sensible critique. Me & my neighbour were preparing to do some research about that. We got a good book on that matter from our local library and most books where not as influensive as your information. I am very glad to see such informat

kfc coupons United States

10/19/2009 11:40:10 AM #

cash loans

Do you make money out of this blog? just curious

cash loans United States

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.5.1.7
Theme by Naveen Kohli

By Categories