Welcome!

AJAX & REA Authors: John Funnell, Bob Little, Kevin Hoffman, Maureen O'Gara, Onkar Singh

Related Topics: AJAX & REA, Java, ColdFusion, Adobe Flex, AJAXWorld RIA Conference & Expo

AJAX & REA: Article

AJAX Reporting Challenges & Solutions with Adobe Flex

Bringing together JavaScript, Flash Player, and Web Services

Now we need to call the operation KeywordSearchRequest providing the data according to the KewordRequest format.

2. Call the Web Service
var ws = com.farata.jsfx.WebServices("MyWebService");
Add the Web Service operation result listener.
ws.addEventListener("serviceresult", onXmlResult);

Prepare the arguments for the call (i.e., as an XML object) to find books that have the work AJAX in their titles:

Var args = '<m:KeywordSearchRequest xmlns:m="http://soap.amazon.com">'
+ ' <KeywordSearchRequest>' + '<keyword>AJAX</keyword>'
+ ' <page>1</page>' + '<mode>books</mode>'
+ '<tag>D3HW0PG66IPLAM</tag>' + '<type>lite</type>'
+ '<devtag>D3HW0PG66IPLAM</devtag>' + '<sort></sort>'
+ '<variations></variations>' + '<locale></locale>'
+ '</KeywordSearchRequest>' + '</m:KeywordSearchRequest>';

Call the "KeywordSearchRequest" Web Service operation.

ws.callService("Amazon", "KeywordSearchRequest", args);

Later in this article I'll show you how to pass the operation's arguments as a JavaScript object instead of XML. Now the data from Amazon comes back and WebService.swf will get something like this:

<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:amazon="http://soap.amazon.com"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body>-<namesp1099:KeywordSearchRequestResponse xmlns:namesp1099="http://soap.amazon.com">
<return xsi:type="amazon:ProductInfo">
<TotalResults xsi:type="xsd:string">355</TotalResults>
<TotalPages xsi:type="xsd:string">36</TotalPages>
<Details xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="amazon:Details[10]">
<Details xsi:type="amazon:Details">
<Url
xsi:type="xsd:string">http://www.amazon.com/gp/product/0596101996%3ftag=D3HW0PG66IPLAM%26link_
code=sp1%26camp=2025%26dev-t=D3HW0PG66IPLAM</Url>
<Asin xsi:type="xsd:string">0596101996</Asin>
<ProductName xsi:type="xsd:string">JavaScript: The Definitive Guide</ProductName>
<Catalog xsi:type="xsd:string">Book</Catalog>
<Authors xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="xsd:string[1]">
<Author xsi:type="xsd:string">David Flanagan</Author>
</Authors>
<ReleaseDate xsi:type="xsd:string">17 August, 2006</ReleaseDate>
<Manufacturer xsi:type="xsd:string">O'Reilly Media, Inc.</Manufacturer>
<ImageUrlSmall xsi:type="xsd:string">http://ec1.images-amazon.com/images/I/11G8BIrxn7L.jpg</ImageUrlSmall>
<ImageUrlMedium xsi:type="xsd:string">http://ec1.images-amazon.com/images/I/21yLdMet2BL.jpg</ImageUrlMedium>
<ImageUrlLarge xsi:type="xsd:string">http://ec1.images-amazon.com/images/I/51OY5KP5ydL.jpg</ImageUrlLarge>
<ListPrice xsi:type="xsd:string">$49.99</ListPrice>
<Availability xsi:type="xsd:string">This item is currently not available.</Availability>
<UsedPrice xsi:type="xsd:string">$18.49</UsedPrice>
</Details>
...

As you can see, there is 355 AJAX books that can be returned as 36 pages, and Amazon has returned the page number one as was requested in the argument object. Parsing this XML will be automatically done for you by the WebService.swf component that will turn it into an object for easy access via dot notation.

A Mini-Tutorial on E4X, a Standardized Processing of XML
Working with XML (SOAP)-based Web Services in AJAX isn't easy: each browser handles XML differently. But consuming Web Services with AJAX can be fun if you delegate XML processing to our WebService.swf component that engages E4X.

In Figure 3 you'll see how ActionScript 3 (we used it in creating WebService.swf) can work with any XML source (i.e. SOAP) using familiar dot notation. This is an example from ActionScript documentation and will give you a feeling of the ease of dealing with XML in ActionScript (for a more detailed explanation of E4X go to Click Here !.


More Stories By Yakov Fain

Yakov Fain is a Managing Director of Farata Systems, consulting, training and product company. He has authored several Java books, dozens of technical articles. SYS-CON Books released his latest co-authored book , Rich Internet Applications with Adobe Flex and Java: Secrets of the Masters in Spring 2007. Sun Microsystems has nominated and awarded Yakov with the title Java Champion. He leads the Princeton Java Users Group. He is an Adobe Certified Flex Instructor. Currently Yakov works on the book for O'Reilly "Enterprise Application Development with Flex". He twits at twitter.com/yfain.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.