7.3. Web Services

A web service is a way of exchanging data between servers with a request and response metaphor. Flex and AIR make invoking web services very easy by managing all of the SOAP packet generation. For a definition of a SOAP packet, please see below. Calling a web service is done by using the <mx:WebService> tag. As previously stated, this tag will handle the creation and parsing of the SOAP packets that are sent and received from the remote server. The example in this section uses a free web service from webservicesx.net.

7.3.1. SOAP

SOAP stands for Simple Object Access Protocol and is a protocol for data exchange in XML format. When data are sent to the remote server invoking a web service, they're sent as a SOAP packet. The results returned from the server are also in a SOAP packet. Here is an example of the SOAP packets that will be used in the example later in this section. Listing 7-10 is an example of a SOAP request, and Listing 7-11 is an example of a SOAP response.

Example 7-10. Example of a SOAP request
POST /stockquote.asmx HTTP/1.1 Host: www.webservicex.net Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://www.webserviceX.NET/GetQuote" <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <GetQuote xmlns="http://www.webserviceX.NET/"> <symbol>string</symbol> ...

Get Beginning Adobe® AIR™: Building Applications for the Adobe Integrated Runtime now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.