I have seen a lot of emails and blog posts with folks wanting to know how to connect their flex application to a remote ColdFusion server. At first I thought this was a really silly question, because its not much different than connecting to a local one. But then I realized that this was clear for me because I was not setting up my projects using the ColdFusion option in the Flex Builder new project wizard.

Because I started my flex 2 adventures on my mac, using only the Flex 2 SDK and the command line compiler, I look at creating my projects a little differently. But also when i begin a project I dont feel its a good idea to commit my self to any one of the RPC services.

So when I create a new flex project I always choose the “Basic” project type. I specify the name of my project and where I want my files to live. I then begin working on my application, building the layout and controls that make up the GUI. WHEN I am ready to look at connecting to a remote service for data processing, I walk through these steps.

  1. Create a “libs” directory at the root of my project. (name and location is really arbitrary)
  2. Copy the services config file from my ColdFusion instance (or another project) to this directory
  3. Add a new option to the compiler settings for the project which specifies the location of the config file. (ie. –compiler.services=libs/services-config.xml)
  4. In my services-config.xml I specify the exact path to the cf server I wish to access in my cf-amf channel definition
    < endpoint uri="http://simb.net/flex2gateway/" class="flex.messaging.endpoints.AMFEndpoint"/ >

I feel this method has several benefits. The first being that my project is now independent of any other projects using the ColdFusion destination on this server. Which means if I change the config file in cf (or in another project) my project will continue to function as I expect. The second benefit is that my application doesn’t have to take into account how this information is set. For instance Mike Nimer posted an excellent way to get rid of the services-config.xml file all together in your application. But I feel his method is quite a bit of work for something a few lines of xml take care of very nicely. And the third point is that I can actually use ANT to change the value of the server path as part of a deployment script, so I can have my application compile for local or remote server usage very easily.

I hope if you were confused about a solution for doing remote cf development in flex this might help you simplify your process. I know for me it did because I didnt realize there was such a problem :)