Adobe Flex 3 Help

About data access

The Flex SDK contains features for accessing server-side data. Flex data access components are based on a service-oriented architecture (SOA). These components use remote procedure calls to interact with server environments, such as PHP, Adobe ColdFusion, and Microsoft ASP.NET, to provide data to Flex applications and send data to back-end data sources.

Depending on the types of interfaces you have to a particular server-side application, you can connect to a Flex application by using one of the following methods:

  • HTTP GET or POST by using the HTTPService component
  • Simple Object Access Protocol (SOAP) compliant web services by using the WebService component
  • Adobe Action Message Format (AMF) remoting services by using the RemoteObject component

Note: Another common name for an HTTP service is a REST-style web service. REST stands for Representational State Transfer, an architectural style for distributed hypermedia systems. For more information about REST, see www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm.

REST-style services

For REST-style services, you use a server resource such as a PHP page, JavaServer Page (JSP) or servlet, or ColdFusion page that receives a POST or GET request from a Flex application using the HTTPService component. That server resource then accesses a database using whatever means are traditional to the particular server technology. The results of data access can be formatted as XML instead of HTML, as might be typical with the server technology, and returned as the response to the Flex application. Flex, Adobe® Flash® Player, and Adobe AIR™ have excellent XML- handling capabilities that let you manipulate the data for display in the Flex application user interface. REST-style services provide an easy way to access a server resource without a more formalized API such as those provided by web services or remote object services. These services can be implemented using any number of server technologies that can get an HTTP request and return XML as the response.

Web services

SOAP-compliant web services are a standardized type of REST-style service. Rather than accessing a PHP, JSP, or ColdFusion page specifically, a Flex application accesses a web service endpoint. Based on published specifications, a web service knows the format in which the data was sent and how to format a response. Many server technologies provide the ability to interact with applications as web services. Because web services comply with a standard, you don't need to know the implementation details of the code with which a Flex application interacts. This is particularly useful for applications, such as business-to-business applications, that require a high degree of abstraction. However, SOAP is often very verbose and heavy across the wire, which can result in higher client-side memory requirements and processing time than working with informal REST-style services.

Remote object services

Remote object services let you access business logic directly in its native format rather than formatting it as XML, as you do with REST-style services or web services. This saves you the time required to expose existing logic as XML. When using Adobe® LiveCycle™ Data Services ES, Vega, or ColdFusion, a Flex application can access a Java object or ColdFusion component (which is a Java object internally) directly by remote invocation of a method on a designated object. That object on the server can then deal with its native data types as arguments, query a database from those arguments, and return its native data types as values.

Another benefit of remote object services is the speed of communication across the wire. Data exchanges still happen over HTTP or HTTPS, but the data itself is serialized into a binary representation. This results in less data going across the wire, reduced client-side memory usage, and reduced processing time.

Considerations for accessing server-side data

Consider the following key considerations when you are creating an application that must access server-side data:

HTTPService components

HTTPService components let you interact with HTTP services, which can be any HTTP URI that accepts HTTP requests and sends responses. Although you can use the HTTPService component to consume different types of responses, it is typically used to consume XML. You can use an HTTPService component with any kind of server-side technology, including PHP pages, ColdFusion Pages, JavaServer Pages, Java servlets, Ruby on Rails, and Microsoft ASP pages.

HTTPService components are a good option for working server-side technologies that are accessible over HTTP and are not available as a web service or remoting service.

HTTPService components let you send HTTP GET, POST, HEAD, OPTIONS, PUT, TRACE, and DELETE requests and include data from HTTP responses in a Flex application. Flex does not support mulitpart form POSTs.

You can use an HTTPService component for CGI-like interaction in which you use HTTP GET, POST, HEAD, OPTIONS, PUT, TRACE, or DELETE to send a request to a specified URI. When you call the HTTPService object's send() method, it makes an HTTP request to the URI specified in the url property, and an HTTP response is returned. Optionally, you can pass request arguments to the specified URI.

The following example shows an HTTPService component that calls a PHP page. This HTTPService component provides two request arguments, username and emailaddress. Additional code in the application calls the PHP page to perform database queries and inserts, and to provide the data returned from the PHP page to the user interface of the Flex application.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application>
...
    <mx:HTTPService id="userRequest" url="http://server/myproj/request_post2.php" useProxy="false" method="POST">
        <mx:request xmlns="">
            <username>{username.text}</username>
            <emailaddress>{emailaddress.text}</emailaddress>
        </mx:request>
    </mx:HTTPService>
</mx:Application>

For more information on creating HTTP services and accessing them with HTTPService components, see Using HTTPService components.

WebService components

WebService components let you access web services, which are software modules with methods, commonly referred to as operations. Web service interfaces are defined by using XML. Web services provide a standards-compliant way for software modules that are running on a variety of platforms to interact with each other. For more information about web services, see the web services section of the World Wide Web Consortium site at www.w3.org/2002/ws/.

Flex applications can interact with web services that define their interfaces in a Web Services Description Language (WSDL) document, which is available as a URL. WSDL is a standard format for describing the messages that a web service understands, the format of its responses to those messages, the protocols that the web service supports, and where to send messages.

The Flex web service API generally supports SOAP 1.1, XML Schema 1.0 (versions 1999, 2000, and 2001), WSDL 1.1 rpc-encoded, rpc-literal, and document-literal (bare and wrapped style parameters). The two most common types of web services use RPC-encoded or document-literal SOAP bindings; the terms encoded and literal indicate the type of WSDL-to-SOAP mapping that a service uses.

Flex applications support web service requests and results that are formatted as SOAP messages and are transported over HTTP. SOAP provides the definition of the XML-based format that you can use for exchanging structured and typed information between a web service client, such as a Flex application, and a web service.

If web services are an established standard in your environment, you can use a WebService component to connect to a SOAP-compliant web service.

The following example shows a WebService component that calls a web service. This WebService component calls two web service operations, returnRecords() and insertRecord(). Additional code in the application calls the web service to perform database queries and inserts and to provide the data returned from the web service to the user interface of the Flex application.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application>
...
    <mx:WebService
        id="userRequest"
        wsdl="http://server:8500/flexapp/returncfxml.cfc?wsdl">
        <mx:operation name="returnRecords" resultFormat="object"
            fault="mx.controls.Alert.show(event.fault.faultString)"
            result="remotingCFCHandler(event)"/>
        <mx:operation name="insertRecord"
            result="insertCFCHandler()"
            fault="mx.controls.Alert.show(event.fault.faultString)"/>
    </mx:WebService>
</mx:Application>

For more information about accessing web services with WebService components, see Using WebService components.

RemoteObject components

RemoteObject components let you access the methods of server-side objects, such as ColdFusion components (CFCs), Java objects, PHP objects, and .NET objects, without configuring the objects as web services. You can use RemoteObject components in MXML or ActionScript.

You can use RemoteObject components with LiveCycle Data Services ES, Vega, or ColdFusion. To access a remote object, you specify its fully qualified classname or ColdFusion component name in the RemoteObject component's source property, or you use the destination property to specify a logical name that is mapped to a fully qualified Java class name in a server-side configuration file, the remoting-config.xml file.

You can also use RemoteObject components with PHP and .NET objects in conjunction with third-party software, such as the open source projects AMFPHP and SabreAMF, and Midnight Coders WebORB. Visit the following websites for more information:

When you use a RemoteObject tag, data is passed between your application and the server-side object in the binary Action Message Format (AMF).

The following example shows a RemoteObject component that calls a web service. This WebService component calls two web service operations, returnRecords() and insertRecord(). Additional code in the application calls the web service to perform database queries and inserts and to provide the data returned from the web service to the user interface of the Flex application.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application>
...
    <mx:RemoteObject
        id="userRequest"
        destination="ColdFusion"
        source="flexapp.returncfxml">
        <mx:method name="returnRecords" result="returnHandler(event)"
            fault="mx.controls.Alert.show(event.fault.faultString)"/>
        <mx:method name="insertRecord" result="insertHandler()"
            fault="mx.controls.Alert.show(event.fault.faultString)"/>
    </mx:RemoteObject>
</mx:Application>

For more information about creating remoting services and accessing them with RemoteObject components, see Using RemoteObject components.