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
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:
- What is the best type of service to use? For more information, see HTTPService components, WebService components, and RemoteObject components.
- What is the best way to pass data to a service? For more information, see Explicit parameter passing and parameter binding.
- How do you want to handle data results from a service? For more information, see Handling service results.
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.
http://livedocs.adobe.com/flex/3/html/data_access_2.html#193905
No comments:
Post a Comment