Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Using Amazon's Web Services Toolkit in Your Windows Forms Applications

Amazon's free Web services let you query and display data from Amazon's Web site in your own applications. Despite the name, you're not limited to using Web services in Web applications. See how to use Amazon's new Web services in desktop applications, and see why Web services are becoming increasingly important in all applications.


advertisement
arlier this year, Amazon quietly exposed a set of Web services that can be used to allow any application to find and display Amazon product information. The Web services are compatible with any language capable of posting and receiving data via HTTP and consuming either HTML or SOAP-based XML.

Amazon's Web Services 2.0 let you build query and storefront applications that use the services to supply up-to-date information on Amazon products. The free download includes a number of examples—including some complete applications—that show how to use the services from Java, .NET, PHP, and VB/VBA.

Getting Started
First, download the toolkit and unzip the result. That creates a directory structure containing the files you'll need for development. Next, navigate back to Amazon's download site and click the Apply For a Free Developer's Token link. You must send your developer's token along with each request. You cannot run the sample application without a developer's token.



There are two basic methods for querying an Amazon Web service: with an HTTP request (XML over HTTP or REST) and via SOAP. In addition, you can pass an XSLT stylesheet along with the request and get back HTML (or other XSLT output) formatted according to your needs. The XSLT capabilities are currently available only via the REST method, not through SOAP calls. However, that doesn't really matter much for most applications, because you're perfectly free to apply your XSLT stylesheet locally to the SOAP response.

One of the nicest things about Web services is that you don't need to write browser-based applications to take advantage of them. Amazon's Web services are capable of retrieving information about a wide range of Amazon's products and services; however, once you get the idea, they're all similar. It's a little easier to apply the toolkit results to a Web application, and the sample applications in the toolkit show how to do that; so in this article, you'll focus on building a Windows Forms-based query engine that lets users search for programming books and display the results.

Building the Sample Application
The basic plan is to provide a search field where the user can enter keyword search terms and then to call the Amazon service to search for books using those keywords. The application should display a sorted list of titles matching the search request. When the user clicks a title in the list, the application will retrieve the details for the selected title, and display them.

To do this, you need to make two types of requests: a KeywordRequest and an AsinRequest. ASIN is shorthand for "Amazon.com Standard Item Number"—a unique ID assigned to every Amazon product.

Each request has a type, which you can set to the string "heavy" or "lite," and controls the detail level of the returned data. For this application, a "lite" request suffices for the keyword request because you're only going to display titles that match the search request. The lite request type also returns the ASIN, which you can then use to perform an AsinSearchRequest using the "heavy" request type to get all the details for a specific item.

Create a new Windows Forms application and add these items:

  • TxtSearch—a single-line TextBox for the user to enter keyword search terms.
  • LstResults—a ListBox to hold the results of the keyword search query.
  • PnlDetails—a Panel that will hold controls to display the details returned from an AsinRequest.

Next, you need to add a Web Reference to the Amazon Web services. To do that, right-click on the Web References item in Visual Studio's Solution Explorer, select Add Web Reference, and enter the following URL in the Address field of the Add Web Reference dialog:

http://soap.amazon.com/schemas2/AmazonWebServices.wsdl

Press Enter to access the WSDL file for the service. You'll see the results shown in Figure 1.

Figure 1. Creating the WSDL: The Add Web Reference dialog shows the WSDL for the Amazon Web services.

When you do that, VS.NET creates a proxy file (reference.cs) that defines all the classes you need to make SOAP requests and retrieve data from the responses.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date