In using amfphp, I found that I need to create two configuration files: services-config.xml and remoting-config.xml. In the Flex 2 documentation, the former file defines the basic services settings such as security and logging. Destination services definitions should not be defined in the services-config.xml, instead create references in the file to separate specific configuraton files reserved for the different services types to a dedicated file. These files include the data-management-config.xml, messaging-config.xml, and proxy-config.xml. And finally, the latter file is used on of those so called configuration files and defines RemoteObject services. You may also use multiple files of the same type, if it’ll help with maintaining groups of services.
services-config.xml
There are several nodes and attributes for this file. For a complete list, bring up the help index in Flex Builder and search for “Data Service configuration file syntax”. For amfphp, you only need the following defined:
<?xml version="1.0" encoding="UTF-8"?>
<services-config>
<services>
<service-include file-path="remoting-config.xml" />
</services>
<channels>
<channel-definition id="[your channel service id]"
class="mx.messaging.channels.AMFChannel">
<endpoint uri="http:/[your_server]/amfphp/gateway.php"
class="flex.messaging.endpoints.AMFEndpoint"/>
</channel-definition>
</channels>
</services-config>
From Adobe’s documentation, the services node contains the individual data services or references that are the xml files containing the service definitions. It is declared at the top level of the configuration as the child node for services-config node. Inside the services node, is the service-include file-path node. This provides the service file locations and their path is relative to the directory containing the services-config.xml file. As an aside, if you don’t want to break up the definitions, you could include them using the service as a child of the services node. But based on all the other documentation I’ve read, just break up the definitions into managable smaller files. (I’m sure there’s a reason for this other then scalability, let me know and I’ll update this post.)
The channels node provides information about the data transportation between the server and the clients. The channel-definition node defines the message channel that can be used to transport the data with it’s id attribute should match the one defined in the service definition and it’s class attribute being the fully qualified AS3 class for the message channel, which is the AMF in our case. The others are RTMP, AMF polling, Secure RTMP, Secure AMF, HTTP, and Secure HTTP. Per the Configuring message channels documentation, you can actually pair any type of service with any type of channel. Next, the endpoint node is where the client should begin requesting the service with it’s URI attribute pointing to the url of the service and class attribute is the fully qualified AS3 class for the endpoint. The url points to AMFPHP’s gateway.php file.
And that’s it for the service-config file.
remote-config.xml
Just like the services-config file, there are lot of nodes and their associated attributes that are allowed for the remote-config file, which again only references “RemoteObject” calls. To find the Adobe documentation, do a search for “Understanding destination configuration”. The following example is the only thing needed to make a call from our Flex application:
<?xml version="1.0" encoding="utf-8" ?>
<service id="[my flash remote id]"
class="flex.messaging.services.RemotingService"
messageTypes="flex.messaging.messages.RemotingMessage">
<default-channels>
<channel ref="[your channel service id]"/>
</default-channels>
<destination id="categoryService">
<properties>
<source>com.momentstar.service.CategoryDao</source>
</properties>
</destination>
</service>
So a destination is object/service that you connect to using <mx:RemoteObject>, <mx:WebService>, or <mx:HTTPService> tags or Actionscript code. The service node defines the type of service with the id attribute is your arbitrary value, class and messageTypes referring to the RemoteObject.
The default-channels node and it’s child channel correspond to the channel-definition found in the services-config. Next, the destination node and the id attribute is what is used and referred to in your MXML/AS3 code. And finally, within the destination noe is the properties node, where you provide the source node that contains the qualified class name of our AMFPHP service.
Using the files in the compilation
Next, is to tell your application to use the configuration files. When using mxmlc, add -services option with the path to the services-config.xml file. In Flexbuilder, go to the Project, then Properties, and select the Flex Compiler option and in the Additional compiler arguments text box, where you should add something like:
-services=./WEB-INF/flex/services-config.xml
So the next thing is to use the above definitions in the Flex application. One thing I’d like to ask is how do you make different service destination calls and display them in some datagrid. Right now, I’ve only been making one service call per screen in my Flex application. If anyone has tips, again, just let me know!
References:
http://www.flex.org/documentation/