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);
}
}
}
}
976e3207-e769-4e8e-ae52-e03e258f197b|0|.0
Views: 5142
Tags:
WCF | ECommerce