Accessing ColdFusion Components with FlexProducts affected
Flex allows developers to communicate to back-end servers in multiple ways. A ColdFusion Component (CFC) in ColdFusion MX can be exposed externally, either as a web service or through Flash Remoting. In many cases, Flash Remoting may be the better option for performance since Flash Remoting uses Action Message Format (AMF), the optimized binary protocol. This TechNote explains how to access a CFC both as a web service and through Flash Remoting.
This TechNote provides sample MXML code for accessing a CFC through a web service and through Flash Remoting. The CFC that is used resides inweb_root/myappdir/components/mycfc.cfc.
For Flex to access the web service, the path to the CFC is needed and ?wsdl must be appended to the end of the URL, as shown in the following code.
<mx:WebService id="usersCFC" wsdl="http://127.0.0.1/myappdir/components/mycfc.cfc?wsdl" showBusyCursor="true">
<mx:operation name="getAllUsers" result="userResultHandler(event.result)" fault="userFaultHandler(event.fault)"/></mx:WebService>
If you instead want to invoke the same CFC through Flash Remoting, you can use the code in the example shown below. Theendpoint attribute of<mx:RemoteObject> contains the URL to the Flash Remoting gateway on the ColdFusion server. The source attribute points to the location of the component.
<mx:RemoteObject id="usersCFC" endpoint="http://127.0.0.1/flashservices/gateway" source="myappdir.components.mycfc" showBusyCursor="true"><mx:method name="getAllUsers" result="userResultHandler(event.result) fault="userFaultHandler(event.fault)"/></mx:RemoteObject>
It is simple to switch between either one of these approaches in your application without changing other existing code. However, there are issues to be aware of.
One issue you may encounter is related to how ColdFusion handles web services. All variables returned from a ColdFusion web service will be in uppercase. With Flash Remoting, they are returned in exactly the same case as they are typed. For example, if you returned a query with two columns, (FirstName, LastName), when ColdFusion returns the data through a web service call, the columns will be all uppercase, (FIRSTNAME, LASTNAME). If Flash Remoting is used to return the data, then the columns will appear exactly as they appear in the database, (FirstName, LastName). MXML is case sensitive, so it is possible that you may run into a problem with case sensitivity.
Flash Player security can be another stumbling block. If the Flash Remoting gateway is on a different domain than the originating domain the Flex SWF was loaded from, then a crossdomain.xml file will need to be placed in the web root of the Flash Remoting server. In simple terms, you will run into a problem if Flex is on one machine and ColdFusion is on another. You can find details on the crossdomain.xml file in the Flash Player security features section on LiveDocs, as well as the Developer Center article Security Changes in Macromedia Flash Player 7.
Additional Information
Doc ID
(tn_19356)
Last updated
2005-01-05
Products affected
