Using Named Services to access back-end data (http://www.markme.com/cc/archives/004474.cfm)
As discussed in previous posts, a Flex application can access back-end data using three different approaches:
1. Web Services
The WebService component in the Flex class library allows your application to consume any SOAP-based web service.
For example:
<mx:WebService id="googleWS" wsdl="http://api.google.com/GoogleSearch.wsdl"/>
2. Remote Objects
The RemoteObject component in the Flex class library allows your application to invoke methods in Java objects. You don't have to expose these objects as web services.
For example:
<mx:RemoteObject id="myRO" source="mypackage.MyClass"/>
3. XML over HTTP
The HTTPService component in the Flex class library allows your application to send a traditional HTTP request to a server and consume the HTTP response (for example, an XML document) returned by that server.
For example:
<mx:HTTPService id="myBlog" url="http://www.markme.com/cc/index.rdf"/>
Using Named Services
The examples above work well. However, hardcoding URLs in your application is not a good idea if you are concerned with the maintainability of your application. Named services represent a better approach. They allow your application to point to services using logical names. Mappings between logical names and actual resources are defined in WEB-INF\flex\flex-config.xml.
Using named services, the three examples above could be rewritten as follows:
<mx:WebService id="googleWS" serviceName="GoogleWS"/>
<mx:RemoteObject id="myRO" named=" MyRemoteObject"/>
<mx:HTTPService id="myBlog" serviceName="MyBlogSrv"/>
We would then add the three following entries in WEB-INF\flex\flex-config.xml
<service name="GoogleWS">
<wsdl>http://api.google.com/GoogleSearch.wsdl</wsdl>
<endpoints>
<endpoint>{context.root}/services/CatalogWS</endpoint>
</endpoints>
<use-custom-authentication>true</use-custom-authentication>
<allow-unnamed-access>false</allow-unnamed-access>
</service>
<object name="MyRemoteObject">
<source> mypackage.MyClass </source>
<type>stateful-class</type>
<use-custom-authentication>false</use-custom-authentication>
<allow-unnamed-access>true</allow-unnamed-access>
</object>
<service name="MyBlogSrv">
<url>http://www.markme.com/cc/index.rdf </url>
<use-custom-authentication>true</use-custom-authentication>
<allow-unnamed-access>false</allow-unnamed-access>
</service>
Notice that named services also allow you to further configure services. For example, you can specify if the service should allow unnamed access, if a remote object is stateless or stateful, etc.