Skip to main content
January 1, 2011
Question

Post or get question

  • January 1, 2011
  • 1 reply
  • 1169 views

I'm using coldfusion for a web service call from the iphone. I can make this work by using a bunch of separate .cfm files. This however, is getting very ugly quickly. I'm trying to convert this into one .cfm file. Can I do this with functions? Here is what I have:

<cffunction name="FirstFunction" returntype="string">

<cfinvoke

webservice="http://208.112.67.221/CF_WebSvc/justFunction.cfc?wsdl"

method="WelcomeMsg"

returnvariable="strg">

<cfinvokeargument name="name" value=#SentName# />

</cfinvoke>

<cfreturn "this worked" >

</cffunction>

The question is that I'm using a post or get method to get the data. I cannot seem to get the string correct that I'm passing.

http://www.designyournautique.com/webservices/ConsumeJustFunction.cfm/FirstFunction?SentName=Carey

Any ideas? Thanks!

    This topic has been closed for replies.

    1 reply

    BKBK
    Community Expert
    Community Expert
    January 1, 2011

    I think you should stick to one idiom. Choose to use either the remote CFC invocation idiom or the web service invocation idiom. You could use the same CFC in either case. The key requirement is that the method's access attribute be set to remote.

    In the following example, I have saved the CFC in the directory wsTest under the Coldfusion web root.

    JustFunction.cfc

    <cfcomponent>
    <cffunction name="WelcomeMsg" returntype="string" access="remote">
    <cfargument name="name">
    <cfreturn "Welcome to the service, " & arguments.name & "!">
    </cffunction>
    <cfcomponent>

    1) code for web service call, saved as file /wsTest/sendName.cfm:

    <cfset sentName ="BKBK">
    <cfinvoke webservice="http://127.0.0.1:8500/wsTest/JustFunction.cfc?wsdl"
    method="WelcomeMsg"
    returnvariable="strg">
    <cfinvokeargument name="name" value="#SentName#">
    </cfinvoke>

    <cfoutput>#strg#</cfoutput>

    2) for remote CFC invocation, simply browse to:

    http://127.0.0.1:8500/wsTest/JustFunction.cfc?method=WelcomeMsg&name=BKBK

    January 1, 2011

    The cfc document will contain multiple cfc functions. However, the cfm looks like it cannot. The cfm is what will get called by the application consuming the web service. Because there are different variables and numbers of variables being passed I would need each item in the cfm wrapped in a function.

    I guess I'll just end up with a 100 or so cfm files.

    Thanks

    ilssac
    Inspiring
    January 1, 2011

    C-Rock wrote:

    I guess I'll just end up with a 100 or so cfm files.

    Thanks

    You can have as many functions in a single CFC as you care to stuff into it.  And as many of those functions can have the access="remote" property as you like.  But I would be nearly as wary of a single, giant CFC with 100 functions as I would 100 separate files.  I suspect there is a happy medium somewhere of a few CFC files grouping and organizing the various functions in some manner.

    You can have multiple <cffunction...> blocks in a cfm file as well.  But they are not nearly as convenient to external applications as remote functions in a CFC.

    There should be pleny of ways to organize your code so that you DO NOT have 100's of single purpose cfm files.