Flex Architecture Fundamentals Part 2 : Main Means Of Communication Between Flex And The Application Server
Study/Flex 2008/06/15 13:19 |In the first part of this series, we've seen that the server side architecture of a Rich Internet Application typically exposes to its clients a Service API which can also consist of Value Objects (objects that store data, generally representing a DataBase table record).
Today, we'll see the various options a Flex application has to communicate with an application server, with heavy emphasis on the class mapping capabilites of each of these techniques (rather than their actual implementation).
Main Means Of Communication Between Flex And The Application Server
Flex offers both Remote Procedure Call (RPC) asynchronous communication and real-time communication features. Here, we'll focus on RPC communications and RemoteObject-based communications in particular.
The Flex framework proposes three RPC classes for communicating with the application server. Please note that these classes have a different MXML implementation than their AS3 counter-parts : the MXML versions of these classes are subclasses of the AS3 classes, which are all subclasses of the AbstractService class.
For each of these object, you can optionnally decide to provide a destination channel with the use of a service-config.xml file. Basically, it's a file with channel descriptions (mainly the services URIs), and a bunch of other things. Each channel has an ID you can refer to when you instanciate your AbstractService objects. However, since this file is compiled with your application, you cannot change this channel data without recompiling your entire application. To put it otherwise, you can't change your service location without recompiling your application. It's a major deployment issue, so I've decided to rather explain the old school, dynamically configurable way.
HTTPServices
The HTTPService class makes HTTP(S) requests (mostly GET or POST) which may transport various content types, from simple URLencoded variables to more complex data like XML. Basically, this is the choice for Representational State Transfer (REST) web services architecture. Most of the time, an HTTPService object is used to communicate with a simple script or page like a JSP page, an ASP page or a PHP script. Obviously, the value of the HTTPService url property is the URL of this page.
The transported data is sent and received as plain text, meaning that you'll have to map the received data to the corresponding ActionScript data type on the Flex side, and to the corresponding server-side technology data type on the server side. Therefore, it may be a good idea to use a special data exchange format like JSON ( third party libraries, like the corelib on the Flex side and many others on the server side, can help you doing that).
WebServices
The WebService class sends and receives SOAP messages over HTTP. Naturally, this is what you'll use to communicate with SOAP WebServices. To connect to this WebService and call its operations (i.e. its methods), you'll have to hook this object to the WebService's Web Service Definition Language (WSDL) by setting its URI as the wsdl property value.
All ActionScript primitive types and some built-in ActionScript complex types are automatically mapped from and to SOAP/XMLschema data. This process is handled on the Flex side, by the WebService class. This is quite an improvement over HTTPService-based communications where you have to do that job by yourself, or use third party libraries.
However, you'll still have to implement your own mapping procedure for custom classes.
RemoteObjects
The RemoteObject class is responsible for sending and receiving ActionScript Message Format (AMF) data. This technique is also called Remoting.
AMF is not a transfer protocol: it is binary ActionScript. AMF3 is the binary format for AS3, whereas AMF0 was the binary format for AS1 and AS2. Note that AMF3 specifications were open quite recently.
In this case, AMF is transported over HTTP, but it can also be transported over real time communication protocols. Exchanging data using AMF is dramatically faster than any other mean of communication. Take the test : try James Ward's benchmark application.
Besides, it allows the Flex client to send and receive ActionScript strongly typed objects. With Remoting, the ActionScript serialization/deserialization process takes place on the server side. Of course, you'll have to have a server side tool that enables this AMF serialization/deserialization : this is what we call an AMF Gateway (or Remoting Gateway).
With Remoting, you can transport built-in primitve and complex data (as with a WebService) but also custom typed objects. This way, you're able to automatically map a server side Value Object to and from an ActionScript Value Object. To do so, you simply have to add a RemoteClass Meta data to your ActionScript ValueObject Class Definition.
This is what a Flex to application server AMF communication can look like :
Let's take a real world example :
Contrary to what the Flex documentation states, RemoteObject AMF communications are not limited to Java Objects and J2EE servers. Neither do you have to use it with LifeCycleDataServices (LCDS, formerly FlexDataServices) or ColdFusion. Actually, most application server technologies have at least one free and OpenSource AMF Gateway.
So here's a presentation of the main AMF gateways you'll find out there :
WARNING : HTML TABLE DRAMA AHEAD
For some reason I'm still trying to figure out, Drupal doesn't like my Tables. I made my best to make it legible. Sorry for that !
| Name | Technology | Creator/Owner | Free | OpenSource | Notes |
|---|---|---|---|---|---|
| AMFPHP | PHP | AMFPHP team | YES | YES | It used to be the most popular PHP AMF0 gateway. Version 2, which supports AMF3, is still in beta. Many use it anyway, despite of the authentication (lackthereof) issues |
| WEBORB PHP | PHP | The midnight coders | YES | YES | A very good, professional looking AM0 and AMF gateway for PHP which provides a classy service browser with an integrated code generator. WebOrb is a product that exists for other technologies as well. Lacks decent documentation, though. Messaging support under development |
| SABREAMF | PHP | Evert Pot | YES | YES | A popular, mature and stable PHP AMF0 and AMF3 gateway. |
| FLUORINE | .NET | No idea. The Silent group, I guess... | YES | YES | AMF0 and AMF3 gateway. Also provides a partial real-time messaging library à la BlazeDS / LCDS (FluorineFX, supports RTMP protocol). |
| WEBORB .NET | .NET | The midnight coders | YES | NO | AMF0 and AMF3 gateway. Also supports messaging (RTMP protocol). WebOrb is a product that exists for other technologies as well (see WEBORB PHP). |
| Open AMF | Java / J2EE | Not sure exactly (SourceForge page admins are jcalabrese, kbaker, sullis). Please tell me if you know more. | YES | YES | AMF0 gateway. Began as a port of AMFPHP. As far as I know, the project is discontinued. |
| Granite Data Services | Java / J2EE | Franck Wolff (I guess) | YES | YES | AMF3 gateway. It has a pretty good reputation among Java developers. Messaging support under developement. |
| RED5 | Java / Ruby / Python (..?) | The RED5 team | YES | YES | RED5 is more than a traditional AMF gateway. It's a server that's mainly aimed at providing an free and openSource alternative to Flash Media Server (in other words, it streams sound and video). It's been under development for quite a long time, and has a strong community. |
| WEBORB JAVA | Java / J2EE | The midnight coders | YES | NO | AMF0 and AMF3 gateway. Supports messaging, and data management. WebOrb is a product that exists for other technologies as well (see WEBORB PHP) |
| LifeCycle Data Services (LCDS) | Java / J2EE | Adobe | NO | NO | The official Adobe AMF0 and AMF3 J2EE gateway. The succesor of Flex data Services which, itself, was the result of the separation between Flex IDE and server services, after Macromedia's acquisition by Adobe, in 2005. Supports, messaging, data management, and lots of other features. |
| BlazeDS | Java / J2EE | Adobe | YES | YES | The other official Adobe AMF0 and AMF3 J2EE gateway ;). It's a free alternative to LCDS but does not support all its features (espacially data management). Announced in early 2008. Current version is a release candidiate. |
| AMF::Perl (aka Flash::Flap) | Perl / Python | Simon Ilyushchenko, Adrian Arva | YES | YES | Another port of AMFPHP. I frankly don't know much about it but I guess it's AMF0. |
| PyAMF | Python | NickJoyce, ThijsTriemstra, ArnarBirgisson | YES | YES | AMF0 and AMF3 gateway for Python. Supports RTMP. |
What's important not to miss here is that each AMF gateway has its own implementation particularities, independent from the technology they serve. Authentication, error management, RTMP support, for exemple, may be really different from one to the other. Be extra carefull when it's time to choose. Strong community support is mostly important since you'll probably find yourself struggling to make them work the first times. A good idea might be to encapsulate the gateway dependencies in a different class, when it's possible.
In the third (and most important) part of this series, we'll see how to architecture our Flex client application.
Additional References
SOAP to AS3 mapping in Flex on the LiveDocs
http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/js/html/wwhelp.ht...
Charlie Key on Transmitting data between Flex and PHP using JSON
http://www.adobe.com/devnet/flex/articles/flex_php_json.html
출처 - dehats
댓글을 달아 주세요