Personal tools

Views

Flex:Accessing Data

From Adobe Labs

This technology shipped on June 27, 2006 and is no longer hosted on Labs. Most of the supporting content for this release can be found on the Adobe.com website.

This article contains important information about how to access data from applications built with the Adobe® Flex™ framework and Adobe® Flex™ Builder™ 2.

Table of contents

Introduction

The single most important thing to remember about working with data in Flex applications is this: Flex applications do not directly connect to a database. You use Flex facilities to send or receive data (typically in XML format) from a server. Flex includes three primary ways of exchanging data with remote servers:

RPC services

Flex provides three ways of sending and receiving data by using remote procedure calls (RPC). These are the HTTPService, WebService, and RemoteObject tags. The first two can be used by any application built in Flex Builder 2. The RemoteObject tag requires Flex Data Services to process the RemoteObject requests.

Flash Player Security

Adobe® Flash® Player does not allow an application to receive data from a domain other than the domain from which it was loaded, unless it has been given explicit permission. If you load your application (SWF file) from http://mydomain.com, it would not be able to load data from http://yourdomain.com. The only exception is when the server you are contacting has implemented a crossdomain.xml file, which explicitly gives Flash permission to access it. This security sandbox prevents malicious use of the capabilities of Flash Player. JavaScript uses a similar security model to prevent malicious use of JavaScript.

When you need to access data from a Flex application, you have three choices:

  1. Add a crossdomain.xml file to the server with the data.
  2. Upload your SWF file to the same server as the data service.
  3. Create a proxy on your server that calls the data service, and put your SWF file on the same server as the proxy.

Using crossdomain.xml files

A crossdomain.xml file is an XML file that provides a way for a server to indicate that its data and documents are available to SWF files served from certain domains, or from all domains. The crossdomain.xml file must be in the web root of the server that the Flex application is contacting. For more information about configuring crossdomain.xml files, see the technote on the Macromedia website: http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=tn_14213.

Setting up your own proxy

Another way to manage Flash Player security is to use a proxy. Adobe® Flex™ Data Services provides a complete proxy management system for Flex applications. You can also create a simple proxy service by using a web scripting language such as ColdFusion, JSP, PHP, or ASP.

All the proxy service needs to do is pass requests to the remote service, and pass responses from the remote service back to Flash Player. For more information about creating your own proxy, see http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=tn_16520.

During development, one common technique is to host the proxy on your local machine. To do this, you will need to be running a web server and a web scripting language on your local machine.

Setting up Flex Builder to use a proxy

After you set up a proxy, you must ensure that your SWF file is being run from the same domain as a proxy. To help with this, you configure Flex Builder in the following way:

  1. Choose a location on your web server for your compiled SWF file along with the associated HTML wrapper and other assets. This must in the same domain as the proxy.
  2. Change your "Run Configuration" to be a URL to this web location. To do this:
    1. Select Run > Run.
    2. Select the application to modify settings for.
    3. Deselect the Use Defaults option.
    4. Type your URL in the Run edit box (for example: http://localhost/myApp/myApp.html).
    5. Type the appropriate debug URL into the "Debug" edit box (for example: http://localhost/myApp/myApp-debug.html).
    6. Click Apply, then click Close.
  3. If your proxy server is your local computer, you also should set up your build directory to point to the appropriate folder on your web server.
    1. Right-click on your project in the Navigator view and select Properties.
    2. Click on "Flex Build Path".
    3. Click the Browse button next to the output directory.
    4. Select the appropriate directory (for example: C:\inetpub\wwwroot\myApp\).
    5. Click OK.
  4. If your proxy server is not your local computer, you must copy the contents of the bin directory to your server before running or debugging your program.

Data Managment Service

Data Management Service is included with Flex Data Services. Data Management Service provides a data-centric programming model that automates data synchronization between application tiers, enables real-time data updates, data replication, and occasionally connected application services, and provides integration with data sources through adapters. This feature lets you create applications that work with distributed data, and lets you manage large collections of data and nested data relationships, such as one-to-one and one-to-many relationships. When using Data Management Service, SWF files are typically served from the same server where the Flex Data Services are deployed. As a result, the Flex application can communicate directly with the Flex server without the need for additional proxies or crossdomain files.

See more details on Data Services.

Messaging Services

The publish-subscribe messaging feature, included with Flex Data Services, provides messaging services for collaborative and real-time applications. This feature lets you create applications that can send messages to and receive messages from other applications, including Flex applications and Java Message Service (JMS) applications. Messages can contain text or objects.

Read more about Flex Data Services and messaging.

You can also read about how to get started in the Flex Data Services section of Adobe Labs http://labs.adobe.com/technologies/flexdata_services2/.

Retrieved from "http://labs.adobe.com/wiki/index.php/Flex:Accessing_Data"