Flex Web Services Question

Posted by Aaron West at 6:30 PM in Flex

I've been doing a good bit of work in Flex 2 lately and I've run into some interesting scenarios with Web Services and CFMX 6.1. Let me preface this by saying I firmly believe many of my issues would not be issues if the hosting server (not this site) was on CFMX 7.0.2. Why? Because I could use Flash Remoting instead of Web Services to hook Flex 2 to my CFC's.

Anyhow, I'm working on this real simple application and I've run into issues where things I would normally do in AS2 in terms of calling CFC's via Flash Remoting do not work in AS3 with Flex 2 and Web Services. There's probably a good reason, but I'm knee deep in this and can't see the forest for the trees. Perhaps someone can set me straight.

Let's say I have a CFC method that has 2 required arguments and 2 optional arguments. The Flex 2 code to create the WebService signature might look like this:

<mx:WebService id="wsGrouping" wsdl="http://url/to/cfc/MyCFC.cfc?wsdl" useProxy="false" showBusyCursor="true">
      <mx:operation name="createNewGrouping" result="createNewGroupingResult(event)">

And, let's say I define a function that sets up these parameters and calls the Web Service method looks like this:

private function assembleDataForGrouping():Boolean {
   var paramsObj:Object = { };
   paramsObj.inventoryGroupingID =;
   paramsObj.siteIDToGroup =;
   paramsObj.allowEdits = 1;
   paramsObj.locationIDToOverride =;
   return true;

Simple enough. This type of parameter passing is something I typically do in Flash 8 with Flash Remoting and CFC's. The CFC method (via remoting) is smart enough to ignore the overall paramsObj Object and map each individual Object property to the appropriate argument in the CFC method. With Web Services in Flex 2, an error is thrown. If you forego passing a vanilla Object and instead nominate each individual property in the Web Service call, it works. The code for this type of explicit parameter passing might look like this:

wsGrouping.createNewGrouping.send(,, paramsObj.allowEdits, paramsObj.locationIDToOverride);

Some problems I see with this method relate to optional parameters. What if my CFC method has 2 required parameters and 2 optional parameters? If my CFC method defines the first 2 arguments as required and the last 2 arguments as optional, how do I pass in the 4th optional argument but NOT the 3rd argument? How would ColdFusion know which argument I meant? My first example keeps this problem at bay since the parameters are "mapped" based on their name. But again, this does not work with Web Services and Flex 2.

Along these same lines, what if I wanted to use parameter binding in Flex instead of explicit parameter passing? The code for parameter binding in the WebService method signature would look like this:

<mx:WebService id="wsGrouping" wsdl="http://url/to/cfc/MyCFC.cfc?wsdl" useProxy="false" showBusyCursor="true">
      <mx:operation name="createNewGrouping" result="createNewGroupingResult(event)">

Pretty simple. I define the 4 arguments I want to pass in to the method and bind their values directly to their corresponding components. But, how would you, using parameter binding, optionally pass one parameter? I can't see a way to do it. Nor could you change the value of one passed parameter based on what is selected in a component.

Based on my limited "real world" Flex 2 experience it seems like using explicit parameter passing is the way to go. You have more control over what data you pass to Web Services but you don't really have a choice in how you pass that data. I'd love for someone to comment on this and perhaps shed some light on these examples. Please keep in mind, that this is all dealing with Flex 2, Web Services, and CFMX 6.1. I realize the better solution would be to use Flash Remoting instead of Web Services but FR is not an option when CFMX 6.1 is your back-end (unless I'm really really missing something).

Aaron West's Gravatar
About this post:

This entry was posted by Aaron West on September 12, 2006 at 6:30 PM. It was filed in the following categories: Flex. It has been viewed 8307 times and has 3 comments.

3 Responses to Flex Web Services Question

  1. Dominick

    There are no optional parameters when calling a cfc as a WebService. Additionally, you can't send an object. You have to send each parameter and if there is a parameter that is "optional", you have to pass a null and detect this on the server. I know this isn't the answer your looking for, but this is how it is. Hope this helps clarify a confusion about cfmx webservices.

  2. Twiggy

    This does appear to be "how it is". I wonder if there is any word on it.

    I don't really like flash remoting using CFCs because it binds me to CF
    and it also has the same issues. It also doesn't allow you to do any kind
    of load balancing if you have objects (CFCs) hosted on differnt subsystems.

  3. Flash Remoting is ridiculously better than Web Services when the conversation surrounds Flex 2. There is simply no comparison. That said, you are correct that at the moment you can officially only use ColdFusion as your middle-tier. However, there are several open source remoting efforts underway that may appeal to you. As far as your last comment goes, I'm not sure how that relates at all to Flash Remoting or Web Services. Regardless of which method you use, ColdFusion operates mostly the same. Sure there are all the added benefits of your ColdFusion function makeup (as mentioned above) but most other things are held equal. Can you explain what you mean further?