Chapter 9: Consuming Web Services with Flash

Overview

Web services allow organizations to provide information to the public using the Internet. Organizations use them so that they can provide information from their own systems in a controlled way. Web services can provide public data but restrict access to sensitive information. Users make a request, and the web service provides the response in an XML document. The response is a stream of information rather than a physical document. This process is referred to as consuming a web service.

You can use web services to consume many different types of information, including currency exchange rates, weather information, stock quotes, and Google search results. Imagine being able to create Flash applications that search Google or Amazon, or a Flash-based shopping cart that provides up-to-date exchange rates. You could use Flash to display up-to-the-minute information about your companys stock prices or about the local weather. As an author, I can use Flash to find out the sales ranking and database details for any books Ive written.

These are all examples of how you might include web services in your Flash applications. You can search using your favorite search engine to locate public web services. You can also see a list of web services at www.flash-db.com/services/ and www.xmethods.com/.

There are many ways to consume a web service. One option is to display the XML content in a web browser. However, youre more likely to use server-side pages or a web application to process the XML from the web service. Flash can receive the web service response and display the XML data in a movie.

You can find out what web services are available through a companys Universal Description, Discovery, and Integration (UDDI) registry. The UDDI contains a description of the web services that are available and lists the way that you can access them.

Web Services Description Language (WSDL) describes web services in a standard XML format. The WSDL document for a web service explains what operations you can perform, what parameters you need to supply, and what information youll receive.

There are a number of protocols for accessing web services, including Simple Object Access Protocol (SOAP), Representational State Transfer (REST), and RSS. SOAP uses formatted XML messages to request and receive information from web services. REST is a way to work with web services that allows you to make requests from a web service through a URL. Another option is RSS (which stands for either Rich Site Summary, RDF Site Summary, or Really Simple Syndication). RSS makes information available through XML news feeds using standard XML elements.

At the time of writing, SOAP is the probably the most common protocol for consuming web services. Flash has native support for SOAP-based web services over the HTTP protocol. This means that Flash will generate the SOAP request and process the response automatically. There are two types of SOAP requests: Remote Procedure Call (RPC) and Document. Flash supports both types as long as the web service response includes datatypes that Flash recognizes.

Flash can connect to a WSDL file to find what operations are available through the SOAP web service. You can use the WebServiceConnector data component, or you can write ActionScript to generate the SOAP request. As with the other data components , youll only have access to the WebServiceConnector if you own Flash Professional. Well show you how to consume SOAP web services later in this chapter.

You can also consume REST web services in Flash. Because of the security restrictions with the Flash Player, youll normally do this through a server-side page that proxies the XML data and makes it available locally. Chapter 4 has more information about Flash Player security.

If you want to include content from a web service in Flash, you have several choices:

  • Use the WebServiceConnector component.

  • Write ActionScript to use either the WebServiceConnector or Web Service classes.

  • Write server-side pages to query the web service.

  • Use Flash Remoting.

Whichever approach you decide to use, youll need to consider the security issues with the Flash Player when consuming web services. You may also need to change the Flash publish settings to allow you to access remote networks.

In this chapter, well explore all of the alternatives for working with web services except Flash Remoting. Well start by looking at how you can consume a REST web service using a server-side language. Ill use ASP.NET, but you can use any other language, such as ColdFusion or PHP. Well also look at consuming an RSS feed without a server-side page. Well work with the WebServiceConnector component and use it to consume currency exchange rates and weather information. Finally, Ill show you how to use ActionScript to work with the WebServiceConnector and Web Service classes. By the end of this chapter, youll have built several applications that consume web services.



Foundation XML for Flash
Foundation XML for Flash
ISBN: 1590595432
EAN: 2147483647
Year: 2003
Pages: 93
Authors: Sas Jacobs

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net