Jump to content

How to Work with External Data Services While Using Flex

0
  chco's Photo
Posted Dec 10 2010 09:13 PM

This excerpt from Learning Flex 4 shows you how to work with external data services in Flex.
Although the HTTPService component is a handy resource, you may require more dynamic alternatives from time to time. In fact, Flex applications thrive when backed by a well-tuned server technology and database combination. For such circumstances, the WebService or the RemoteObject components, or even PHP, may prove to be the perfect solution for your application.

Note: If your interests require very specific data, you might be surprised by what you find if you do a little digging. For example, the National Oceanic and Atmospheric Administration (NOAA) provides weather information via web services at http://www.nws.noaa.gov/xml/, and the USGS recently unveiled a water data web service as an experimental beta at http://waterservices.usgs.gov/.

Web Services

The HTTPService component lets you access services that have a URL—particularly data that can be viewed in a browser, such as HTML or XML. However, a number of web services exist that are accessible only through an XML standard called SOAP. Although a bit heavier than other services, SOAP-based services are particularly prevalent in business-to-business applications, and you may find it necessary to connect to a SOAP web service in Flex.

To easily access SOAP web services, use the WebService component. You might also find the Connect to Web Service command useful. This command can point to a WSDL URL and automatically generate a good deal of code for you.

Note: WSDL stands for Web Services Description Language, and is a common language model for describing web services. It specifies what operations are available for a service and the format of the service’s response.

To access this command, select Data→Connect to Web Service. From there you’ll be prompted with a dialog box that asks you where you’d like to place the code that’s generated, and asks for a URL to a WSDL description file. Flash Builder will generate code necessary to access the web service.

Note: For a directory of web services that you can use, check out http://www.xmethods.net or http://www.webservicelist.com.

RemoteObject

Another powerful data access component is the RemoteObject, which lets you easily connect to server-side Java (Java EE or J2EE) or ColdFusion. You gain a number of benefits by using remote objects, which are maps to Java objects and ActionScript objects. This means actual data types such as Number or Date can be transferred across the wire intact. Another huge benefit of remote objects is that data can be compressed over the wire. That results in speedier access to large amounts of data. Among other benefits, you also can use data push, which allows you to listen for data changes on a remote server and get that new data automatically. Imagine an email application that didn’t require you to manually get new mail, but would show you new mail as soon as it arrived.

Note: Java EE stands for Java Enterprise Edition, and is a version of the Java platform made for server-side processing. ColdFusion is actually a Java EE application, enabling you to create server code in a markup language.

To use RemoteObject component, you must set up your application to use remote object access on a specific web server. Typically this is done when creating a new Flex project.

PHP and HTTPService

PHP remains a popular server solution, and due to the ease of which it connects to MySQL, it’s also a very accessible technology—not to mention that both platforms can be obtained free of charge. If you’re paying for a web hosting service, chances are good you already have access to both PHP and MySQL. For all of these reasons, PHP makes an excellent choice for an external service engine.

Creating an Application from a Database

If you're using ColdFusion, PHP, J2EE, or ASP.NET, you're in luck. Flash Builder can actually generate server-side code for you, letting you easily connect to data in a database, and even modify that data. You supply the database, and all the necessary code for creating, reading, updating, and deleting records will be written for you—even a simple UI for testing purposes.

For PHP, J2EE, or ASP.NET applications, you must have a database and a web server set up using one of these technologies. Then, all you need to do is open the Data menu and a number of options will present themselves. Once you follow the prompts, an actual Flex application will be created, containing user interface elements and service methods for accessing the host data. You can even use this as a foundation for creating an application.

Learning Flex 4

Learn more about this topic from Learning Flex 4.

Learn Adobe Flex 4 in a fun and engaging way with this book's unique, hands-on approach. Using clear examples and step-by-step instructions, you'll create four applications that demonstrate fundamental Flex programming concepts, including how to enhance user interaction with ActionScript, create and skin a user interface with Flex's UI components, manage dynamic data, connect to a database using server-side script, and deploy applications to both the Web and the desktop.

See what you'll learn


Tags:
0 Subscribe


0 Replies