Working with Data Services (Loading Data at Runtime)

Flex applications are generally distributed applications. That means several computers work in conjunction to create one system. For example, all Flex applications have a client tier (discussed shortly) that runs on the user’s computer in the form of an .swf running in Flash Player. In most cases, the client tier communicates with a server or servers to send and retrieve data. The servers provide what are called data services, which are essentially programs that have public interfaces (APIs) whereby a client can make a request to a method of that program. When a client makes such a request, it's called a remote procedure call, or RPC.

There are many types of data services. In its simplest form a data service could consist of a static text file or XML document served from a web server. A slightly more sophisticated data service might be a dynamic XML document generated via a server-side script or program, such as a PHP or ASPX page. Many data services require greater sophistication. One of the most common types of such a sophisticated data service is the web service. Web services use XML (generally in the form of SOAP) as a messaging format, and they enable RPCs using HTTP for requests and responses. Although a SOAP web service is an example of a standards-based data service, many types of data services don’t necessarily conform to a particular standard set by the W3C. Many programs on the Web, for example, expose primitive data services that use arbitrary messaging formats and protocols. One such program is used by MapQuest, a popular mapping web site. For instance, you would use the following URL to view a MapQuest page with a map of Los Angeles:

http://www.mapquest.com/maps/map.adp?country=US&city=Los+Angeles&state=CA

Notice that the query string uses arbitrary parameters to determine what to map. Therefore, if you wanted to display a map of New York, you would change the city and state parameter values in the URL as follows:

http://www.mapquest.com/maps/map.adp?country=US&city=New+York&state=NY

Flash Player is capable of making RPCs to many types of data services. For example, Flash Player can make requests to any web resource using HTTP, which means it can make requests to many primitive data services such as a static or a dynamic XML document, or the MapQuest example mentioned previously. That also means it can make requests to web services. Moreover, the Flex class library simplifies requests to most data services.

In addition to the types of data services previously mentioned, Flex applications can also make calls to methods of classes on the server, using a technology called Remoting. Remoting uses a binary messaging format called AMF, which is supported natively by Flash Player. AMF has all the benefits of SOAP, but since it is binary, the bandwidth overhead is greatly reduced. And since AMF is natively supported by Flash Player, no special coding is necessary to use Remoting data services from the client tier. However, for a Remoting data service to be available to the client tier, it must be made accessible via a piece of software that resides on the server and can read and write AMF packets as well as delegate the requests to the correct services. You can find a list of Remoting server products in Chapter 17.

Get Programming Flex 3 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.