Top Banner
Flex Data Communications Nick Kwiatkowski, Michigan State University
27

Flex Data Communications Nick Kwiatkowski, Michigan State University.

Dec 31, 2015

Download

Documents

Elijah Carr
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Flex Data Communications Nick Kwiatkowski, Michigan State University.

Flex Data Communications

Nick Kwiatkowski, Michigan State University

Page 2: 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!

Page 3: Flex Data Communications Nick Kwiatkowski, Michigan State University.

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

Page 4: Flex Data Communications Nick Kwiatkowski, Michigan State University.

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

Page 5: Flex Data Communications Nick Kwiatkowski, Michigan State University.

HTTPService

• How it is used:– Place the HTTPService tag at the application

or component level (root level) of your current MXML document.

Page 6: Flex Data Communications Nick Kwiatkowski, Michigan State University.

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.

Page 7: Flex Data Communications Nick Kwiatkowski, Michigan State University.

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.

Page 8: Flex Data Communications Nick Kwiatkowski, Michigan State University.

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.

Page 9: Flex Data Communications Nick Kwiatkowski, Michigan State University.

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

Page 10: Flex Data Communications Nick Kwiatkowski, Michigan State University.

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

Page 11: Flex Data Communications Nick Kwiatkowski, Michigan State University.

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!

Page 12: Flex Data Communications Nick Kwiatkowski, Michigan State University.

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**

Page 13: Flex Data Communications Nick Kwiatkowski, Michigan State University.

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.

Page 14: Flex Data Communications Nick Kwiatkowski, Michigan State University.

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.

Page 15: Flex Data Communications Nick Kwiatkowski, Michigan State University.

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.

Page 16: Flex Data Communications Nick Kwiatkowski, Michigan State University.

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

Page 17: Flex Data Communications Nick Kwiatkowski, Michigan State University.

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.

Page 18: Flex Data Communications Nick Kwiatkowski, Michigan State University.

ColdFusion Demo

What is it, and how is it used with Flex.

Page 19: Flex Data Communications Nick Kwiatkowski, Michigan State University.

ASP.NET Demo

What is it, and how is it used with Flex?

Page 20: Flex Data Communications Nick Kwiatkowski, Michigan State University.

PHP Demo

What is it, and how is it used with Flex?

Page 21: Flex Data Communications Nick Kwiatkowski, Michigan State University.

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.

Page 22: Flex Data Communications Nick Kwiatkowski, Michigan State University.

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

Page 23: Flex Data Communications Nick Kwiatkowski, Michigan State University.

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.

Page 24: Flex Data Communications Nick Kwiatkowski, Michigan State University.

ColdFusion and Flex

• Right click on a table to template out CFCs for your Flex apps

• Demo!

Page 25: Flex Data Communications Nick Kwiatkowski, Michigan State University.

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

Page 26: Flex Data Communications Nick Kwiatkowski, Michigan State University.

Where to find more info

• Adobe Flex 2: Training from the source– Jeff Tapper, et al

Page 27: Flex Data Communications Nick Kwiatkowski, Michigan State University.

Questions?