Web DevCenter
oreilly.comSafari Books Online.Conferences.
MySQL Conference and Expo April 14-17, 2008, Santa Clara, CA

Sponsored Developer Resources

Web Columns
Adobe GoLive
Essential JavaScript

Web Topics
All Articles
Scripting Languages

Atom 1.0 Feed RSS 1.0 Feed RSS 2.0 Feed

Learning Lab

Consuming Amazon with Flash Remoting

by Jason Michael Perry

Editor's Note - In this article you'll learn how to create a responsive UI that can search and display results using Web Services and Flash Remoting. Jason will show you how to build the interface and manipulate the XML Web Service. This tutorial requires Flash MX, Flash Remoting, and a free Amazon.com associate account.

The Power of XML Web Services

As a webmaster, I frequently find myself forcing third party web tools to integrate into my Web site. In the end, I may disguise the obvious subdomain name or that slight change in the consistency of my design, but I shouldn't have to. I should request and get seamless integration from any vendor into my Web site. Well, several companies are finally coming around with XML Web Services.

XML Web Services allow you to hook into a company's infrastructure and share data through the Web. This differs from other methods because it embraces W3C's standards for transportation and descriptions known as SOAP and WSDL. Now companies can embrace this as a way to aggregate real time information. Imagine purchasing financial software off the shelf and seamlessly getting credit card balances and bank statements from different companies. Imagine having full control of that affiliate solution's look and feel.

Related Reading

Web Services Essentials
Distributed Applications with XML-RPC, SOAP, UDDI & WSDL
By Ethan Cerami

The power of XML Web Services doesn't stop there. It also allows companies to decrease paper and time by instantly transmitting data. For example, Monster.com, HotJobs.com, and CareerBuilder.com could all receive new job posting for your company via an exposed XML Web Service. This allows your Human Resources department to use one tool for writing and sending job posting that works with several job boards as well as brick and motor placement firms.

Macromedia understands this vision and plans to be part of it with Flash Remoting. Flash Remoting leaps years ahead of previous ways Flash grabbed data (remember loadVariable) and allows Flash to integrate with any complex Web application exposed as a XML Web Services, as well as ColdFusion MX, ASP.Net, and J2EE. Now Flash can consume Web Services from any remote source and spit out that data as if it where its own.

Think about this for a second. You can connect to an Amazon.com XML Web Service and create your own Flash store complete with Amazon recommendations, search, product description...the whole nine yards. Or you could create a responsive UI that can search and display results using Google.com's XML Web Service.

And that's exactly what we're going to do in this article. Amazon.com recently released a XML Web Service to allow affiliates to better integrate Amazon.com into their Web sites. This provides amazing potential for Amazon.com, as well as affiliates looking to pass Amazon.com's books off as their own. In this tutorial I'll break down Amazon.com's XML Web Service, show you how to establish a connection with Flash Remoting, and help you build a Flash spotlight that dynamically list Amazon.com's books. To follow along with this tutorial, you should download my Flash file and download Amazon's developer kit. You'll also need to register with Amazon for a unique token. Without this token you cannot connect to the XML Web Service.

Analyzing Amazon's XML Web Service

Now that we understand some of the benefits of XML Web Services, let's take a look at Amazon.com's WSDL. A WSDL (Web Service Description Language) is a XML vocabulary, and we'll use to provide all the information we'll ever need to know about a XML Web Service. With this we can view the Web Service's functions, its location, and special types. Go to http://soap.amazon.com/schemas/AmazonWebServices.wsdl to view the WSDL description.

<xsd:complexType name="KeywordRequest">
    <xsd:element name="keyword" type="xsd:string" />
    <xsd:element name="page" type="xsd:string" />
    <xsd:element name="mode" type="xsd:string" />
    <xsd:element name="tag" type="xsd:string" />
    <xsd:element name="type" type="xsd:string" />
    <xsd:element name="devtag" type="xsd:string" />
    <xsd:element name="version" type="xsd:string" />

At first this WSDL may look a little intimidating, but it's surprisingly simple and easy to understand. First, look at the <xsd:complexType> tag. This tag allows Amazon to create new types that provide additional functionality or grouping native types like strings and integers can't provide. In the this case, we have an object that stores keyword search criteria. Each type within this object is a string type. In the above code snippet, the elements wrap to the following keyword data:

  • keyword - the keyword used in the search.
  • page - Which page of the search results you'd like to see.
  • mode - The store this search should include. A list of valid stores is available in the developer kit.
  • tag - "webservice-20" this denotes that this is a web service call.
  • type - "lite" or "heavy" response. This corresponds with the amount of data you want returned.
  • devtag - Your unique token. A free token is available at Amazon's web site here.
  • version - Currently "1.0"

I will not breakdown the other object defined types but the request wrapper objects are defined in the sample Flash download.

<message name="KeywordSearchRequest">
  <part name="KeywordSearchRequest" type="typens:KeywordRequest" />
<message name="KeywordSearchResponse">
  <part name="return" type="typens:ProductInfo" />

Another important element in the WSDL is the <message> tag; it provides information on the functions available from our Web Service. In the above code snippet, the <part> element represents the parameters for the function named KeywordSearchRequest and the type this parameter is. You should also notice that we have two separate <message> elements, one named KeywordSearchRequest and the other KeywordSearchResponse. Request should be used when calling the function while response provides the type returned.

By combining our <message> and <xsd:complexType> elements, we can understand the parameters the function requires. The next section will shed light on how to implement these objects in Flash.

Pages: 1, 2

Next Pagearrow