Skip to main content
Participant
April 29, 2009
Question

Flex remoting call to ColdFusion to call another web service.

  • April 29, 2009
  • 2 replies
  • 779 views

I am new to ColdFusion and am planning an ambitous project that would use ColdFusion as a consumer. I am using Flex as a front end and, through Flash Remoting, would like to call a cfc  that, in turn, calls a web service, but I don't see how to return the web service data back to Flex. I am guessing that the remoting call from within Flex will expect a return, and the web service call from within ColdFusion will expect a return variable, and that ColdFusion will automatically return to the return variable to the Flex call. Can someone please comment on this and send me in the right direction? Thanks.

    This topic has been closed for replies.

    2 replies

    Inspiring
    April 29, 2009

    Michael nailed the first part of the issue for you: set the access attribute of your CFC method to "remote" and that method becomes accessible to Flex via Flash Remoting (it also "turns" the CFC into a valid web service, or at least that method).

    To return data from ColdFusion to Flex, you would need to declare a return type for your CC method and then return data from the function. Here's a very simple example:

    <cffunction name="getHW" access="remote" returntype="string">

      <cfreturn "hello world" />

    </cffunction>

    Similarly, you can return a variable (as opposed to the string literal)

    <cffunction name="getHW" access="remote" returntype="string">

      <cfset myvar = "hello world" />

      <cfreturn myvar />

    </cffunction>

    The long and short of it is that you will want to be sure and return data from the CFC method. For you, maybe it's something like this:

    <cffunction name="getWSStuff" access="remote" returntype="struct">

      <cfset var mydata = '' />

      <!--- calling web service here and storing returned data in mydata struct --->

      <cfreturn mydata />

    </cffunction>

    Question for you: Is there an inherent benefit to calling a CFC method which will call a another web service over using Flex to call the Web Service directly (mx:WebService or mx:HTTPService tags would go right to the web service)?

    Not sure if you knew this or not but you can build AS3 classes in Flex Builder 3 (v. 2 does this too, I think) based on a WSDL file. You are then able to use those AS3 classes to call your web service, handle the returned results (Flex has SOAP Encoding and Decoding classes to convert Flex data to a usable set of data for the web service).

    If you need some sample code from Flex on how to call either the CFC or the Web Service and handle returned data, feel free to let me know and I can provide (spent the past few months working on a massive Flex app that uses Web Services with complex data types as the back-end)

    Celumbra1Author
    Participant
    April 29, 2009

    Thanks for the replies.

    In this particular case, there is a reason to log on to the web

    service from a single source instead of directly from Flex.

    I suspected that the cfreturn variable would automatically handle the

    transfer of data back to the Flex app, but I just didn't know how the

    asynchronous handling of the web service call, simultaneously with the

    remote call would be handled. Looks like it is automatic.

    Thanks again.

    Michael Borbor
    Inspiring
    April 29, 2009

    Hi there, the process is very straightforward, just create a CFC and set access="remote", then in flex call it using a RemoteObject.