270 likes | 447 Views
Flex Data Communications. Nick Kwiatkowski, Michigan State University. Data Communications. Why communicate? Your Flex applications most likely want to have fresh data from a database or other webservice You may need to send current data to your end-users Three-Tiered applications
E N D
Flex Data Communications Nick Kwiatkowski, Michigan State University
Data Communications • Why communicate? • Your Flex applications most likely want to have fresh data from a database or other webservice • You may need to send current data to your end-users • Three-Tiered applications • Data -> View -> Controller • Your data tier doesn't have to be local!
Data Communication Basics • Flex currently supports three types of data communications with external sources : • XML via HTTP Requests • SOAP Web-Services • AMF / Remote Objects • With this combination, you can virtually talk to any back-end server
HTTPService • The HTTPService MXML tag allows for the most basic communication level between you and a web server • Mostly used for legacy middleware applications and static XML documents • Any application that can generate proper XML on the fly can talk to your Flex app using this tag
HTTPService • How it is used: • Place the HTTPService tag at the application or component level (root level) of your current MXML document.
HTTPService • Common Parameters: • id – Used to name the component • url – The full URL to the component • result – The event function that will be fired when the result came back successfully • The XML document will be stored in the event.result object • fault – The event function that will be fired when the result did not come back correctly.
Web-Services • SOAP or Web-Services can easily be called using the <mx:WebService> component. • Web Services allow you to communicate data back to the web-server, and retrieve typed objects (strings, numbers, arrays, queries) • Because it is based on XML, it is very verbose, and often slow for large sets of data.
Web-Services • How it is used: • Place the <mx:WebService> tag at the root level of the document (application or component) that you are working on.
Web-Services • Common Parameters: • id – Used to name the object • wsdl – Points to the WSDL (Web Service Descriptor) file. This file is different for each language • showBusyCursor – Changes the current pointer to a rotating clock to let the user know something is happening
Web-Services • Passing parameters: • You can pass parameters to web-services by naming operations (methods or functions). • The operation tag allows for result or fault functions
Web-Services • Passing Parameters: • You CAN use binding statements within your parameters (to bind to user’s input, for example) • Webservices are Case Sensitive, so make sure that your parameters match case • Some application servers, such as ColdFusion don’t care about case-sensitivity • Watch out with ColdFusion, because it transforms all cases to Uppercase when transmitting data!
AMF • AMF, or Remote Objects are the most efficient way to transmit data between your application server and your Flex Application • Data is transmitted in Binary, so it is fairly compressed • Objects will stay in their native form when transmitted • Very easy to use**
AMF • So, why NOT use AMF? • Only ColdFusion, ActionScript and Java are supported by Adobe. • PHP has an open source solution, however. • Fairly hard to setup your environment • Requires files to be copied down from your development / deployment environment • Makes a lot of assumptions that can hurt you your first time through.
AMF • What your need: • You need to get a copy of services-config.xml from your environment. • ColdFusion this is your <webroot>/WEB-INF/flex/ • JRun this is <webroot>/<ear file>/WEB-INF/flex/ • If you do not develop your applications locally, you need to modify this file. • Copy the ColdFusion destination section and my-cfamf sections to meet your needs.
AMF • Services-Config? • This file is compiled into your project and will convert the “destination” portion of your RemoteObject call to the tcp/ip hostname and port numbers • Depending on how this file looks, your application can be very portable, or not portable at all.
AMF • How it is used: • Just the same as WebService, but instead of the WSDL parameter, you use the destination and source parameters • Destination = Destination from the services-config.xml file • Source = If using ColdFusion, this the path to the CFC, in dot notation
Advanced Communication • By customizing the services-config.xml file, you can also enable some advanced communication • By using the <mx:Producer> and <mx:Consumer> tags, you can “produce” content to other applications or Coldfusion Event Gateways. • This allows for Many-to-One or Many-To-Many applications with little or no work.
ColdFusion Demo What is it, and how is it used with Flex.
ASP.NET Demo What is it, and how is it used with Flex?
PHP Demo What is it, and how is it used with Flex?
ColdFusion and Flex • When using ColdFusion with Flex Builder, there are certain wizards available to the developer which helps make data communications quicker. • These need to be installed manually with Flex Builder; follow the directions in the readme. • You also need to configure the Data Sources within ColdFusion before you can begin.
ColdFusion and Flex • Within the Preferences dialog box, go to the RDS configuration to setup your connection with ColdFusion • Context Root and User Name are un-used unless you are using the Multi-Server version of ColdFusion
ColdFusion and Flex • Open the “RDS Dataview” tab by going to Window -> Show View -> Other -> Coldfusion -> RDS Dataview • You will then be shown all the Data Sources available to Coldfusion. You can browse the data, too! • Double-Click to launch thequery browser.
ColdFusion and Flex • Right click on a table to template out CFCs for your Flex apps • Demo!
Where to find more info • AMF-PHP Project • http://www.amfphp.org • Adobe DevNet • http://www.adobe.com/devnet/flex/ • Adobe LiveDocs • http://livedocs.adobe.com/flex/2/ • Community Flex Project • http://www.cflex.net
Where to find more info • Adobe Flex 2: Training from the source • Jeff Tapper, et al