Why won't Flex Remoting work with ColdFusion?

This question comes in from a reader:

I'm trying to become familiar with Flex remoting and tie to a CFC on the back end.

When I run the flex code and press the button I receive the following error: [RPC Fault faultString="[MessagingError message='Destination 'ColdFusion' either does not exist or the destination has no channels defined (and the application does not define any default channels.)']" faultCode="InvokeFailed" faultDetail="Couldn't establish a connection to 'ColdFusion'"]

I'm not quite sure what the problem is, it could be any number of things. Here are some things I suggested that he take a look a:

  • Services Config: Did he add the services-config file to your Flex Builder project as command line argument? Bring up project properties and select Flex Compiler. The argument should be something like this:

    -services c:/CFusionMX7/wwwroot/weborb30/WEB-INF/flex/services-config.xml

    If not, you'll want to add it.

  • Check Flex Remoting Setup: There could be a problem with the Flex Remoting setup. CAn you load localhost/flex2gateway? If you see a blank page, you're all set. If you see a 404 error, then that is the problem. Is Flash Remoting support enabled from the ColdFusion administrator? Check under Data and Services --> Flex Integration.
  • Code: Check your CFC code. Will it work locally, being invoked from a cfm template? Can you generate a WSDL by loading the CFC in the browser with a ?wsdl argument? Although when using Flash Remoting, the WSDL is not needed, loading the WSDL in the browser will make you aware of potential errors w/ remote access.
  • Paths: Check the case sensitivity of your paths. If the case is wrong, the Flash Player won't find the CFC.

I've run into all sorts of these problems when trying to get this stuff working the first time. However once I made it over that initial hump I never had to look back.

Hey, did you know over at The Flex Show we're giving away a Nintendo Wii Bundle? CT is in the middle of a heat wave, so I'm gonna get out of the non-air-conditioned office and try to find some cooler places to program at.

Comments
Michael's Gravatar We might need more information to help you. What does your my-cfamf section look like in services-config.xml? (you also want to check cf-rtmp, cf-polling-amf and my-cfamf-secure)

The default is
<endpoint uri="http://{server.name}:{server.port}{context.root}/flex2gateway/" class="flex.messaging.endpoints.AMFEndpoint"/>

If you are running the Flex app from a sub folder chances are it can not find the server. You can copy the whole file to another XML file, I have one for each distinct project. i.e. services-config-project1.xml, services-config-project2.xml. This way I can update the config file as needed without breaking other projects.

Let em know if you need more help.
# Posted By Michael | 6/10/08 9:54 AM
joshua cyr's Gravatar I just ran into this over the weekend on my first flex project with remoting. I had that exact error. Turns out I didn't set up my flex project to use CF. I started new project, specified that I would use CF. Then I brought the code in. PRESTO!

I am guessing that Is that related to the Services Config mentioned. Its all quite new to me. :-)
# Posted By joshua cyr | 6/10/08 10:14 AM
Jeffry Houser's Gravatar Michael,

I've never had problems, nor heard of anyone having problems because the Flex app was in a subfolder. The endpoint, as you state above, is an absolute path. I wouldn't expect sub folders to have any affect.

I have heard about people who use the "different file for each project" approach. I've experimented with it myself, but for most of what I'm doing, the default file works fine.
# Posted By Jeffry Houser | 6/10/08 10:15 AM
Jeffry Houser's Gravatar Joshua,

Yes, you're correct. When you create a Flex Builder Project and specify CF as the "server" all it does it add on the services argument to the compiler string.
# Posted By Jeffry Houser | 6/10/08 10:20 AM
joshua cyr's Gravatar Is there a book for Flex and CF? I found my self with all kinds of questions like:

How do I loop over a query with AS3? Is the return type of a query an ArrayCollection? Etc. I am figuring them out of course, but seems like a resource of Flex for CF people would be handy.
# Posted By joshua cyr | 6/10/08 10:23 AM
David's Gravatar Jeff, any idea how to make the "Services Config" variable dynamic, instead of hard coded?

Cheers,

Davo
# Posted By David | 6/10/08 10:49 AM
Jeffry Houser's Gravatar David,

It depends what you mean by dynamics. Techincally this is dynamic

{server.name}:{server.port}{context.root}

The Flash Player figures out where to look for the gateway based on the URL that the swf is served from.

You can also bypass the services config file completely using a method described here: http://blog.mikenimer.com/index.cfm/2007/1/10/Bye-...

But I've never used it.

Joshua,

So far as I know there is no book on Flex and CF. I was toying around with the idea of writing one, but it's not gong to happen anytime soon.
# Posted By Jeffry Houser | 6/10/08 11:23 AM
João Fernandes's Gravatar Jeff, while the Flash player is able to resolve {server.name} and {server.port} at runtime, it doesn't work for {context.root} variable so if you deploy ColdFusion for instance under a /cfusion context-root (or anything else other than /) you should update that variable in the flex builder to get it hardcoded during compile time.
# Posted By João Fernandes | 6/10/08 2:15 PM
Flug's Gravatar ok, ok, thanks a lot guys! I just that I was the only one who is just to dumb to get it worked somehow. Now I am inspired for some new ideas.
# Posted By Flug | 10/14/08 11:29 AM
All Content Copyright 2005, 2006, 2007 Jeffry Houser. May not be reused without permission
BlogCFC was created by Raymond Camden. This blog is running version 5.8.