Flex and ColdFusion: RemoteObjects and WebServices
Once you have a ColdFusion CFC you can call it's methods with a RemoteObject or via a WebService.
RemoteObjects are usually preferred for their performance speed.
Here we'll create a super basic example of calling a CFC from both a WebService and a RemoteObject. The application will simply let you enter your name, click a button, call the CFC and return a welcome message including your name.
To set up our examples, let create a most basic CFC. Let's call this file NEWCFComponent.cfc and this'll be it's contents:
You can see this simply takes the #name# variable that it retrieves and returns the welcome message "Yo, #name#!".
Okay, let's first call this with a WebService. Just create a basic local Flex project.
Here's the main application for that project:
Modify the 'wsdl' attribute of the WebService tag as necessary to point to your CF server.
That's it! Now Run the Flex app, enter your name, click the button and see your welcome message!
Now let's do the same thing but use a RemoteObject.
Create a Flex Project and in the Flex Project Wizard choose 'ColdFusion' for the server type and 'ColdFusion Flash Remoting'. Point the 'Web root' and 'Root URL' to your CF server.
Use the same contents for the Flex application as above except remove the WebService tag and all it's contents, and put this in it's place:
The 'destination' is the remote destination as defined in remoting-config.xml (located in the /WEB-INF/flex directory). 'ColdFusion' is a pre-defined, built-in destination.
The 'source' attribute should point to the location of your CFC starting at the server root. Note that this does not include the CFC extension, just the name of the CFC.
Go ahead and run the app and it should behave just the same as the WebService version we created above, but maybe faster.
If you want to create you own destination you can do that easily. Open remoting-config.xml (located in the /WEB-INF/flex directory and add this destination:
The 'source' attribute should point to the location of your CFC starting at the server root. This should be identical to the 'source' attribute you had in your RemoteObject tag.
Now a couple quick modifications to the RemoteObject and we're good to go:
Notice we just changed the 'destination' attribute to point to our new destination name, and we removed the 'source' attribute because we included that in the of our custom destination in remoting.config.xml.
For now we'll just use the default remote destination configured in remoting-config.xml (located in the /WEB-INF/flex directory)
Posted by Mac Martine on April 2, 2008 11:33 AM|Permalink
I've noticed that if my cfquery is in the method for my cfc, I can't use a variable for the maxrows attribute. But it works if maxrows is hard-coded (ie., maxrows="5". Why?
Comments
Hi,
I've noticed that if my cfquery is in the method for my cfc, I can't use a variable for the maxrows attribute. But it works if maxrows is hard-coded (ie., maxrows="5". Why?
.....
Posted by: Patrick Whittingham | April 7, 2008 10:17 AM