Flex Data Server and CF Flash Remoting together

A common configuration question with Flex2 developers who are trying to use the Flex Data Server and CF is "How do I use FDS and Flash Remoting calls with CF, in the same app?". The reason this gets confusing is because both Flex and CF have their own version of the services-config.xml file, and you can only point to one file in your flex builder project. So which one do you use?

First off, do not try to merge the CF and Flex2 servers into the same instance. In other words if you find yourself trying to merge the web.xml files, like you did with CF and Flex 1.5 - STOP! Don't do it. You don't need to do it with flex2. Instead you want set up your servers and your project like this.

1) Configure CF on 1 instance/server
2) Configure FDS on 2nd instance/server
3) Point your project at the services-config.xml in the FDS instance.

Ok at this point you can easily call FDS destinations which uses CF (or not). Now to also make Flash remoting requests to CF.

4) Define the destination and channel with Actionscript, instead of letting the compiler do it when it is pointed at the CF version of the services-config.xml

To create you own ChannelSet the code would look something like this.

public var cSet:ChannelSet;

public function initApp()
{
cSet = new ChannelSet();
var customChannel:Channel = new AMFChannel("my-cfamf", http://localhost:8500/flex2gateway/);
// Add the Channel to the ChannelSet. cSet.addChannel(customChannel);
foo.channelSet = cSet;
}


<mx:RemoteObject
id="foo"
destination="ColdFusion"
source="com.foo.component" />
Note: You can always use this ChannelSet technique instead of the -services compiler flag too. And you can use it, if you want to use something like FlashVars to dynamically change the endpoint url too.

Comments
Jim Pickering's Gravatar You're a saint and a hero. Thanks for sharing.
# Posted By Jim Pickering | 7/20/06 6:34 PM
João Fernandes's Gravatar Thank you Mike for this info,

Many of us were stuck how to implement this without having FDS throwing errors all over.

Thank you, thank you, thank you!
# Posted By João Fernandes | 7/21/06 3:21 PM
jasen Martin's Gravatar This is a god send, I thought It was just me missing something...but know, sooo many hours wasted, so many hours saved. Now we can get to having some fun!! Thanks again
# Posted By jasen Martin | 10/3/06 11:19 AM
Nick Hippe's Gravatar Hello Mike,

I setup the two instances (fds,cf) and pointed my project at the services-config.xml in the fds instance but I cannot seem to call any cfc in the cf instance. I am just trying to get something simple working like a helloworld.

Nick
# Posted By Nick Hippe | 10/9/06 1:21 PM
Mike Nimer's Gravatar you want to talk to CF over FDS, not remoting, right? Make sure you have the coldFusion-adapter and the destination in services-config.xml set up right.

Also Start both servers from the command line, that way you can see if there are any errors during startup.

If you want to call CF with Flash Remoting, then you need to point to the FDS services-config.xml. But you need to define the endpoint url and channel in your code directly. (instead of letting flex pull it out of the services-config.xml).

hth
# Posted By Mike Nimer | 10/9/06 8:01 PM
Ryan's Gravatar I'd like to call CF with Flash Remoting, however, I'm receiving a Destination 'ColdFusion' not accessible over channel 'cf-amf' error when trying to invoke a method on my Remote Object. I have a destination defined in the FDS services-config.xml called ColdFusion using the coldfusion.flash.adapter.ColdFusionAdapter adapter. If i remove the destination configuration, then I receive a flex error stating I need a destination defined. Thoughts?

Thanks,
Ryan
# Posted By Ryan | 1/15/07 5:58 PM
Paul's Gravatar I will PAY somebody good money to help me figure this all out. I'm trying to get the Ben Forta's Phone app working. I've read all other blogs and help advice and it still doesn't work. There is a crucial piece of the puzzle missing and I think it's related to the services-config. I'm hosting with crystaltech.com and they seem to be as clueless as I am.

The test.cfm dumps OK, which is a start. See http://208.106.227.101/Phones/bin/CF/test.cfm

But the "Phones" app itself just shows a blank grey screen after the initializing bar finishes loading. See http://208.106.227.101/Phones/bin/phones.html

If anybody can work with me to get this going, I'd appreciate it. Name your price! I have documented every step of what I have done so far including screen shots of all path entries etc in FlexBuilder2. From this, somebody might be able to see where I'm going wrong.

Email me at xxxchinabuy01@yahoo.comxxx. (Remove three x's from each end first).

Paul
# Posted By Paul | 3/29/07 1:41 AM
boybles's Gravatar How would you set polling serializations and timeouts dynamically?
# Posted By boybles | 5/2/07 10:42 AM
mike nimer's Gravatar I'm not sure if I understand you questions. But if it's what I think it is, things like polling are defined in the service-config.xml channel-definition elements. So in my example I'm creating a channel linked to the "my-cfamf" channel-definition. You can easily create a new channel in your actionscript that points to a polling channel-definition.

does that answer you question?
# Posted By mike nimer | 5/2/07 3:05 PM
boybles's Gravatar Well we're now defining the channel in as. not in service-config, right? so where would the polling timeout and serializations go in the code below?

public function initApp()
{
cSet = new ChannelSet();
var customChannel:Channel = new AMFChannel("my-cfamf", http://localhost:8500/flex2gateway/);
// Add the Channel to the ChannelSet. cSet.addChannel(customChannel);
foo.channelSet = cSet;
}
# Posted By boybles | 5/2/07 3:33 PM
mike nimer's Gravatar I guess I don't know what parameters you are talking about. Where do you traditionally set them, in the MX:RemoteObject tag? In the Services-config.xml.

however, taking a guess I think I see the confusion, you said
>Well we're now defining the channel in as. not in service-config, right?

that is wrong. We still have to define the channel in the services-config.xml. So the server will work correctly. This is just a different way to link the client to it. What my code is doing for you is removing the requirement to link the client to the services-config.xml in the compiler arguments. And allows you to change the url or path at runtime, which is not allowed with the standard -services compiler argument (which is how all of the docs explain it).

All of the settings in the services-config.xml are used by the server to operate properly. So they still need to be defined. All the client cares about is what url do I use to access the server. Why the flex team decided to use the same file for the client configuration and server configuration is what causes all of the headaches (especially if your not developing locally).
# Posted By mike nimer | 5/2/07 3:55 PM
boybles's Gravatar ahhh...I see. That helps a lot. I'll try it out. Thanks for walking us through this!
boybels
# Posted By boybles | 5/3/07 3:26 AM
boybles's Gravatar Mike, when I add the adapters/detinations to the FDS services-config.xml file, I get a
"Could not pre-load servlet: MessageBrokerServlet flex.messaging.config.ConfigurationException: channel not found for reference 'my-cfamf' in destination 'ColdFusion'..." error when starting FDS.


Following is the code I pasted between the <sevices></services> tags. What am I doing wrong??

Boybles

<service id="coldfusionsamples-service"
class="flex.messaging.services.RemotingService"
messageTypes="flex.messaging.messages.RemotingMessage">
<adapters>
<adapter-definition id="cf-object" class="coldfusion.flash.messaging.ColdFusionAdapter" default="true"/>
</adapters>
<destination id="ColdFusion">
<channels>
<channel ref="my-cfamf"/>
</channels>
<properties>
<source>*</source>
<!-- define the resolution rules and access level of the cfc being invoked -->
<access>
<!-- Use the ColdFusion mappings to find CFCs, by default only CFC files under your webroot can be found. -->
<use-mappings>false</use-mappings>
<!-- allow "public and remote" or just "remote" methods to be invoked -->
<method-access-level>remote</method-access-level>
</access>
<property-case>
<!-- cfc property names -->
<force-cfc-lowercase>false</force-cfc-lowercase>
<!-- Query column names -->
<force-query-lowercase>false</force-query-lowercase>
<!-- struct keys -->
<force-struct-lowercase>false</force-struct-lowercase>
</property-case>
</properties>
</destination>
</service>
# Posted By boybles | 5/3/07 7:15 AM
boybles's Gravatar Also, when I paste the channel definition in, I get this error: "Could not pre-load servlet: MessageBrokerServlet [1]flex.messaging.MessageException: Cannot create class of type 'coldfusion.flash.messaging.ColdFusionAdapter'.Type 'coldfusion.flash.messaging.ColdFusionAdapter' not found."

How can I help it find he adapter??

thanks,
boybles
# Posted By boybles | 5/3/07 7:22 AM
mike nimer's Gravatar Are you trying to add it to the services-config.xml under the flex server war, or under the ColdFusion server way? ColdFusion ships flex2 inside of it, so you need to add these to the services-config.xml under the CF server. If you want to call java classes, then you would configure the flex services-config.xml.
# Posted By mike nimer | 5/3/07 12:48 PM
needfornews's Gravatar Try NeedForNews.com, a new comprehensive news aggregator.
http://needfornews.com/top_search.php
http://vidslib.com/
# Posted By needfornews | 3/27/08 6:23 AM
rssnewsdigest's Gravatar Try rssnewsdigest.com, a new comprehensive news aggregator. With NeedForNews, you don ’t really have to go anywhere else.
http://rssnewsdigest.com/top_search.php
http://realwebnews.com/
# Posted By rssnewsdigest | 4/2/08 9:47 AM
theofficenews's Gravatar most popular trends on one site
http://theofficenews.com
# Posted By theofficenews | 4/9/08 6:04 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.001.