Flex, ColdFusion - RemoteObject HelloWorld Application
For a while now when I have a new ColdFusion Flex scenario set up and need to do a quick check on connectivity I use the cool app provided by Kyle Quevillon available here. Thing is over time I noticed more and more people hitting the a problem with the basic connectivity of Flex and ColdFusion. Also if tweaks are needed for either the RemoteObject source url or the actual cfc itself, it can become a real pain going back into Flex, retyping in new values, rebuilding and finally uploading to the remote server (if not testing locally obviously).
So I decided to come up with my own small application which overcomes these issues and offers a simple solution for testing Flex and ColdFusion connectivity with little knowledge required to use. Also the app feeds the RemoteObject URL and CFC name so there is no need to have to go back into Flex and recompile, or even amend the app for redistribution to another server, easy!
First up this app tests the flex2gateway simply by allowing the user to type in their domain name with the expected result of a blank page. If that doesn’t work we need to stop right there and deal with that issue first (this is not a solutions application). Next the user can enter the directory structure to their cfc i.e. Context Root –> CFC containing directory. They then enter the CFC name they want to hit. This CFC need only contain the following script:
1 2 3 4 5 6 7 |
|
If the remote call is successful we should see a message output detailing the successful URL, a success flag and the returned String from the CFC. Any faults will be displayed in the same window.
Lastly, all of this is built using PureMVC so if you want to learn more about structuring Flex applications that connect to ColdFusion making remote calls and handling resulting data, viewSource is available and the source files are also attached!
source * Further note
The application takes advantage of a alternative method of connecting to ColdFusion from Flex than the standard mxml RemoteObject. I have created a RemoteDelegate class that acts as the portal to ColdFusion stating the method to be called and use the IResponder interface for handling responses to the remote calls. If a Proxy class with an instance of the delegate class is calling multiple methods in the RemoteDelegate, only 2 methods are required in the Proxy class: result and fault. Then a simple switch or if conditional can be used to filter through the remote call responses and handle accordingly. This I found to be (a) a damn site easier (b) reduced the amount of methods I had to define (c) enabled easier scalabilty (d) enabled me to re-use the classes in many other applications with ease!*