View comments | RSS feed
Contents > CFML Reference > ColdFusion Tags > cfinvoke PreviousNext

cfinvoke

Does either of the following:

This tag works as follows:

This tag can pass parameters to a method in the following ways:

Extensibility tags

 

<!--- Syntax 1 - this syntax invokes a method of a component. --->
<cfinvoke
component = "component name or reference"
method = "method name"
returnVariable = "variable name"
argumentCollection = "argument collection"
...>
OR
<!--- Syntax 2 - this syntax can invoke a method of a component only
from within the component. --->
<cfinvoke
method = "method name"
returnVariable = "variable name"
argumentCollection = "argument collection"
...
>
OR
<!--- Syntax 3 - this syntax invokes a web service. --->
<cfinvoke
webservice = "URLtoWSDL_location"
method = "operation_name"
username = user name"
password = "password"
timeout = "request timeout in seconds" proxyServer = "WSDL proxy server URL proxyPort = "port on proxy server" proxyUser = "user id for proxy server" proxyPassword = "password for proxy server" inputParam1 = "value1"
inputParam2 = "value2"
...
returnVariable = "var_name"
...>
OR
<!--- Syntax 4A - this syntax invokes a component.
This syntax shows instantiation with the cfobject tag.
This cfinvoke syntax applies to instantiating a component
with the cfobject tag and to instantiating a component
with the createobject function. --->
<cfobject
component = "component name"
name = "mystringname for instantiated object">
<cfinvoke
<!--- value is object name, within pound signs --->
component = "#mystringname for instantiated component#"
method = "method name"
returnVariable = "variable name"
argumentCollection = "argument collection"
...
>
OR
<!--- Syntax 4B - this syntax invokes a web service.
This syntax shows instantiation with the cfobject tag.
This cfinvoke syntax applies to instantiating a web service
with the cfobject tag and to instantiating a web service
with the createobject function. --->
<cfobject
webservice = "web service name"
name = "mystringname for instantiated object"
method = "operation_name">
<cfinvoke
<!--- value is object name, within pound signs --->
webservice = "#my stringname for instantiated web service#" timeout = "request timeout in seconds" proxyServer = "WSDL proxy server url proxyPort = "numeric port on proxy server" proxyUser = "string user id for proxy server" proxyPassword = "string user password for proxy server" >

cfargument, cfcomponent, cffunction, cfinvokeargument, cfobject, cfproperty, cfreturn

ColdFusion MX 6.1: Added the following attributes: timeout, proxyServer, proxyPort, proxyUser, and proxyPassword.

ColdFusion MX: Added this tag.

Attribute

Req/Opt

Default

Description

component

See Usage section

 

String or component object; a reference to a component, or component to instantiate.

method

See Usage section

 

Name of a method. For a web service, the name of an operation.

returnVariable

Optional

 

Name of a variable for the invocation result.

argumentCollection

Optional

 

Name of a structure; associative array of arguments to pass to the method.

username

Optional

 

Overrides username specified in Administrator > Web Services.

password

Optional

 

Overrides password specified in Administrator > Web Services.

webservice

Required

 

The URL of the WSDL file for the web service.

timeout

Optional

 

The timeout for the web service request, in seconds

proxyServer

Optional

http.proxyHost system property, if any.

The proxy server required to access the webservice URL.

proxyPort

Optional

http.proxyPort system property, if any.

The port to use on The proxy server.

proxyUser

Optional

http.proxyUser system property, if any

The user ID to send to the proxy server.

proxyPassword

Optional

http.proxyPassword system property, if any

The user's password on the proxy server.

input_params ...

 

 

Input parameters. For each named input parameter specify paramName=paramValue.

Note: If you do not specify any the proxy attributes, and a corresponding system property is set (typically in the JVM startup arguments) ColdFusion uses the system property value.

The following table shows when you can use each attribute:

This attribute is required, optional, ignored, or invalid:

For this cfinvoke tag syntax:

Syntax 1

Syntax 2

Syntax 3

Syntax 4A

Syntax 4B

component

Required

Optional

Invalid

Required

Invalid

method

Required

Required

Required

Required

Required

returnVariable

Optional

Optional

Optional

Optional

Optional

argumentCollection

Optional

Optional

Optional

Optional

Optional

username

Ignored

Ignored

Optional

Ignored

Optional

password

Ignored

Ignored

Optional

Ignored

Optional

webservice

Ignored

Ignored

Required

Ignored

Required

timeout

Invalid

Invalid

Optional

Invalid

Optional

proxyServer

Invalid

Invalid

Optional

Invalid

Optional

proxyPort

Invalid

Invalid

Optional

Invalid

Optional

proxyUser

Invalid

Invalid

Optional

Invalid

Optional

proxyPassword

Invalid

Invalid

Optional

Invalid

Optional

input_params ...

Optional

Optional

Optional

Optional

Optional

If the component attribute specifies a component name, the component with the corresponding name is instantiated, the requested method is invoked, and then the component instance is immediately destroyed. If the attribute contains a reference to an instantiated component object, no instantiation or destruction of the component occurs.

On UNIX systems, ColdFusion searches first for a file with a name that matches the specified component name, but is all lower case. If it does not find the file, it looks for a file name that matches the component name exactly, with the identical character casing.

Method arguments can be passed in any of the following ways. If an argument is passed in more than one way with the same name, this order of precedence applies:

  1. Using the cfinvokeargument tag
  2. Passing directly as attributes of the cfinvoke tag (they cannot have the same name as a registered cfinvoke attribute: method, component, webservice, returnVariable)
  3. Passing as struct keys, using the argumentCollection attribute

For example, the params struct contains three keys: a=1, b=1, c=1. The following call is evaluated as if the arguments were passed to the method in the order a=3, b=2, c=1:

<cfinvoke ... a=2 b=2 argumentCollection=params>
      <cfinvokeargument name="a" value="3">
   </cfinvoke>

Note: The following cfinvoke tag attribute names are reserved; they cannot be used for argument names: component, method, argumentCollection, and result.

1

This example uses Syntax 1.

<!--- immediate instantiation and destruction --->
<cfinvoke 
   component="nasdaq.quote" 
   method="getLastTradePrice" 
   returnVariable="res">
   <cfinvokeargument 
      name="symbol" 
      value="macr">
</cfinvoke>
<cfoutput>#res#</cfoutput>

2

This example uses Syntax 1.

<!--- passing the arguments using argumentCollection --->
<cfset args = StructNew()>
<cfset args.symbol = "macr">
<cfinvoke 
   component="nasdaq.quote" 
   method="getLastTradePrice" 
   argumentCollection="#args#" 
   returnVariable="res">
<cfoutput>#res#</cfoutput>

3

This example uses Syntax 2.

<!--- called only from within a component, MyComponent--->
<cfinvoke
   method = "a method name of MyComponent"
   returnVariable = "variable name">

4

This example uses Syntax 3.

<!--- using cfinvoke to consume a web service using a ColdFusion component --->
<!--- put the following code in a ColdFusion page named wscfml.cfm:--->
<cfinvoke 
   webservice='http://www.xmethods.net/sd/2001/BabelFishService.wsdl'
   method='BabelFish'
   translationmode="en_es" 
   sourcedata="Hello world, friend"
   returnVariable='foo'>
<cfoutput>#foo#</cfoutput>

For more information on the BabelFish web service example, see Using Web Services in Developing ColdFusion MX Applications.

5

This example uses Syntax 4A.

<!--- separate instantiation and method invocation; useful for 
   multiple invocations using different methods or values--->
<cfobject 
   name="quoteService" 
   component="nasdaq.quote">
<cfinvoke 
   component="#quoteService#" 
   method="getLastTradePrice" 
   symbol="macr" 
   returnVariable="res_macr">
<cfoutput>#res#</cfoutput>
<cfinvoke 
   component="#quoteService#" 
   method="getLastTradePrice" 
   symbol="mot" 
   returnVariable="res_mot">
<cfoutput>#res#</cfoutput>

Contents > CFML Reference > ColdFusion Tags > cfinvoke PreviousNext

ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.

Comments


twillerror said on Dec 3, 2003 at 12:50 PM :
When you hit a .NET webservice via SOAP that returns an XML packet that packet is converted into a Java class file with a get and set method for each element. This is a part of apache.axis which ColdFusion is using to implement soap.

There does not seem to be a way to get the raw XML which is annoying. We generally use CFHTTP get methods instead which returns the straight XML, but have a drawback when the service returns an error. Since the code returns an error code of 500 and the content is the error message. A cfcatch around the cfhttp and a throwonerror cannot access cfhttp.filecontent and therefore the error message is dropped. We had to implement our own error handling for it.

I thought there was some changes in 6.1 to make working with .NET style web services easier. Can someone elaborate.
jrunrandy said on Dec 4, 2003 at 12:17 PM :
Correct. CF doesn't provide access to the raw XML.

The CFMX 6.1 Release Notes say :

... includes the ability to specify timeouts and proxy settings, and to invoke over SSL.
csteinola said on Mar 10, 2004 at 3:15 PM :
I'm a bit stumped.

I'm trying to add some security to my CFC web service. I entered a username and password in Administrator for the specific web service entry under Administrator -> Data & Services -> Web Services

I figured that I could then pass the username/password values to the web service via CFINVOKE:

<cfinvoke
webservice = "#myWebService#"
method = "getFunction"
username = "username"
password = "password"
returnVariable = "returnVar">


But the documentation states that those values are to "override (the values) specified in Administrator > Web Services".

What does "override" mean? Does this somehow reset or otherwise ignore the settings in Administrator? That certainly isn't what I'm after. Can I not simply authenticate by passing these values?
jrunrandy said on Mar 11, 2004 at 9:57 AM :
The username and password come into play if you have used web server security to password protect the directory containing the component. It has nothing to do with ColdFusion authentication (that is, cflogin/cfloginuser specified in application.cfm).

So, username must be defined in whatever user store your web server uses for security (NT domain for IIS, LDAP for iPlanet, for example).

You can find a little more information in the corresponding discussion in the Developing Applications with ColdFusion manual: http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/webser32.htm
hiremaga said on Jun 8, 2004 at 6:51 PM :
This is in response to the first post which refers to inability to get the raw XML. I have been able to do this quite easily using the code below:

<cfinvoke webservice="http://somewebsite/WebService.asmx?WSDL"
method="GetMethod"
returnvariable="returnVar"/>

<cfset responseArray = returnVar.get_any()>
<cfset firstElementObject = #responseArray[1]#>
<cfset firstElementXML = XMLParse(firstElementObject.toString())>

I have installed the hotfix described at http://www.macromedia.com/support/coldfusion/ts/documents/webservices_header.htm. This may be why the above code works for me. Hope this helps.
dhemke said on Jun 14, 2004 at 12:17 PM :
I am passing the numeric value 80 into a function within a component and have tried hard-coding the value to 80.

<cfargument name="appPort" type="numeric" required="Yes">

Yet, I getting an error as follows:

Could not perform web service invocation "createApplication" because java.lang.IllegalArgumentException: argument type mismatch

Is this a known bug? I have seen other users complaining of the same problem. What is even more strange is that this error is inconsistent (i.e. numeric values don't always produce this error). Yet it is consistently produced with this particular Web Service method.
ASandstrom said on Jun 14, 2004 at 12:32 PM :
This is a known bug, number 51904.
dhemke said on Jun 15, 2004 at 7:04 AM :
Can you provide any other info on bug 51904? Is there a work around or a hot fix?
CBerlandier said on Jul 13, 2004 at 5:15 PM :
Error 51904. In my instance it is always the third parameter sent, no matter what order the parameters pairs are sent in. Even a parameter with type string defined in the wsdl does not work. Is theie going to be a update soon.
mossy_77 said on Oct 8, 2004 at 2:13 AM :
I am attempting to invoke a webservice on 3 different servers 2 of them don't work. I get:

Could not generate stub objects for web service invocation. We are sorry.
There was an error processing this page.

Date: {ts '2004-10-08 10:00:53'}
Message: Could not generate stub objects for web service invocation.
Detail: Name: java.io.InterruptedIOException: Connection establishment timed out It is recommended that you use a web browser to retrieve and examine the requested WSDL document for correctness. If the requested WSDL document can't be retrieved or it is dynamically generated, it is likely that the target web service has programming errors.

When I place the webservice URL in the browser it displ;ays the soap definition perfectly. Cold fusion can see the webservice but won't allow it to connect. There ore no proxies, passwords or ssl involved.

Also why does it work in one identical environment and not another.

Regardss
Mossy_77
mossy_77 said on Oct 8, 2004 at 2:18 AM :
That previous error was generated when I had:
<cfinvoke webservice="http://#URL.server#/components/web_services.cfc?wsdl"
method="getPreview"
timeout = "200"
strStructName = "#URL.structname#"
returnvariable="structPreview">

When I take the timeout attribute away:
<cfinvoke webservice="http://#URL.server#/components/web_services.cfc?wsdl" method="getPreview"
strStructName = "#URL.structname#"
returnvariable="structPreview">


I still get this error:

Could not generate stub objects for web service invocation. We are sorry.
There was an error processing this page.

Date: {ts '2004-10-08 10:16:05'}
Message: Could not generate stub objects for web service invocation.

java.net.ConnectException: Connection refused: connect It is recommended that you use a web browser to retrieve and examine the requested WSDL document for correctness. If the requested WSDL document can't be retrieved or it is dynamically generated, it is likely that the target web service has programming errors.
Dieterk said on Nov 9, 2004 at 1:48 AM :
mossy_77 : same problem... did you solve the problem ? work around ? On out server, the webservice works great, and after a few hours (it depends) we get that error...
fuehrerm said on Nov 19, 2004 at 7:02 AM :
I am having the exact same problem trying to test a web service that is a simple select statement. If I invoke the component it works fine, but if I invoke the web service it fails with this:

Could not generate stub objects for web service invocation.
Name: http://dbsic/getServerlist.cfc?wsdl. WSDL: http://dbsic/getServerlist.cfc?wsdl. org.xml.sax.SAXException: Fatal Error: URI=null Line=1: Next character must be ">" terminating comment . It is recommended that you use a web browser to retrieve and examine the requested WSDL document for correctness. If the requested WSDL document can't be retrieved or it is dynamically generated, it is likely that the target web service has programming errors.
fuehrerm said on Nov 19, 2004 at 7:18 AM :
Also, one more thing that is "odd" to me, when i browse to this page: http://dbsic/getServerlist.cfc?wsdl

The generated xml has this (notice the targetNamespace is not my servername):
<?xml version="1.0" encoding="UTF-8" ?>
- <wsdl:definitions targetNamespace="http://DefaultNamespace" xmlns:impl="http://DefaultNamespace" xmlns:intf="http://DefaultNamespace"
jlorenti said on Nov 22, 2004 at 11:18 AM :
How does one invoke a _messaging_ Web Service?
I've been able to invoke RPC style Web Services, explicity passing the
required parameters by name, but how is such a mechanism to be
applied to a messaging service?

Do I build the SOAP Envelope myself, and if so, exactly how much of it
do I need to create?

How much of the Envelope does CF handle / What does CF expect the
developer to provide?

Does CF generate the required SOAPContext "request" and "response"
parameters, or will I need to generate those myself?
DerrickStone said on Dec 7, 2004 at 7:15 AM :
If you open that wsdl url directly in a browser, you should see an xml formatted file. If you are seeing the Could not generate stub objects for web service invocation error, there is most likely an error being thrown by your web service cfc. You can read this error by opening the wsdl url - for instance, a common error is to not specify return types for remote functions. The entire cfc must be error free, as it gets compiled to generate the web service. You may need to use mozilla to view the error, as IE can replace an error message with a generic "unable to display page" error.
zombiesandpirates said on Feb 2, 2005 at 11:36 PM :
I'm having trouble call a specific method of a webservice. I can call all the other methods, but the one I want to call exists in a different port/binding.
Is there anyway to specify the port/binding when calling the methd?
Info:
http://live.capescience.com/GlobalWeather/index.html
http://live.capescience.com/wsdl/GlobalWeather.wsdl
My Code:
<cfinvoke webservice="http://live.capescience.com/wsdl/GlobalWeather.wsdl"
method="getWeatherReport"
returnvariable="weather">
<cfinvokeargument name="code" value="CYYZ">
</cfinvoke>
Returns:
Web service operation "getWeatherReport" with parameters {code={CYYZ},} could not be found.

Any thoughs? Thanks
joezizzo1 said on Mar 15, 2005 at 2:50 PM :
For those having trouble calling remote cfc's as web services (ie. strange errors like "must have '>' terminate comment etc...), try adding an Application.cfm file to the directory in which the cfc's exist.

something very simple, like
<cfapplication name = "cfc">

That will allow any aggregator, site partner, etc to access the wsdl file freely, without having any code that is included in your higher level Application.cfm file getting in the way. I don't know, worked for me.
jrunrandy said on May 24, 2005 at 10:01 AM :
FYI, a developer has reported that he had a problem using cfinvoke to
call a web service with multiple arguments, but was able to solve it
by using cfscript instead.
jmk4444 said on Aug 3, 2005 at 9:08 AM :
I am trying to invoke a web service that returns a complex XML document string.,

I try to do the following:
<cfinvoke
webservice="http://www.domain.nett/portal/eig/services/assignment?wsdl"
method="getAssignmentCount"
returnvariable="aAssignmentsType">
<cfinvokeargument name="userID" value="userid"/>
<cfinvokeargument name="userPassword" value="password"/>
</cfinvoke>
<cfset mydoc = XmlParse(aAssignmentsType)>
<cfdump var="#mydoc#">

And I get the following:
An error occured while Parsing an XML document.
Content is not allowed in prolog.

I am brand new to this stuff, please help me understand what is incorrect?
pbedi said on Aug 4, 2005 at 6:55 AM :
Hi,

I am trying to invoke a webservice which is running under Jrun4 using axis framwork and developed in Java. When I call this web service using java client it works fine but when I call it from cf 7 page it throws error:

Here is how I am invoking it:

<cfinvoke method="getTemplateParameters" returnvariable="aString"
webservice="http://5.0.5.1:8300/axis/services/theDna">
<cfinvokeargument name="templatePathName" value="customer/client/headline"/>
<cfinvokeargument name="templateName" value="testtemp.xml"/>
</cfinvoke>
<cfoutput>#aString#</cfoutput>

And the error message is:

Could not generate stub objects for web service invocation.
Name: http://5.0.5.1:8300/axis/services/theDna. WSDL: http://5.0.5.1:8300/axis/services/theDna. org.xml.sax.SAXException: Fatal Error: URI=null Line=2: The markup in the document following the root element must be well-formed. It is recommended that you use a web browser to retrieve and examine the requested WSDL document for correctness. If the requested WSDL document can't be retrieved or it is dynamically generated, it is likely that the target web service has programming errors.

The error occurred in F:\Inetpub\sites\Tracker\testws.cfm: line 60

58 : webservice="http://5.0.5.1:8300/axis/services/theDna">
59 : <cfinvokeargument name="templatePathName" value="customer/client/headline"/>
60 : <cfinvokeargument name="templateName" value="testtemp.xml"/>
61 : </cfinvoke>



And if I change follwing webservice="http://5.0.5.1:8300/axis/services/theDna">
with webservice="http://5.0.5.1:8300/axis/services/theDna?wsdl">

Then I get this error:

Web service operation "getTemplateParameters" with parameters {templatePathName={customer/client/headline},templateName={testtemp.xml},} could not be found.


The error occurred in F:\Inetpub\sites\Tracker\testws.cfm: line 60

58 : webservice="http://5.0.5.1:8300/axis/services/theDna?wsdl">
59 : <cfinvokeargument name="templatePathName" value="customer/client/headline"/>
60 : <cfinvokeargument name="templateName" value="testtemp.xml"/>
61 : </cfinvoke>

And it runs fine from Java client.

Could some one suggest me, what I am missing?

Thanks

Philip
pbedi said on Aug 5, 2005 at 1:40 AM :
Hi,

I found the solution of the problem I had related to calling web service from CF and in my web service, I had complex parameter, and I couldn't figure out how to supply this from CF and now I have changed the interface of WS to accept normal params and it started working.

Thanks

Philip
rajiv_lodha said on Sep 13, 2005 at 6:19 AM :
Handling Complex response
<cfinvoke
webservice="http://webserviceprovider.com/wsdl/?WSDL"
method="method"
returnvariable="ReturnArray">
<cfinvokeargument name="var_name1" value="value1"/>
<cfinvokeargument name="var_name2" value="value2"/>
<cfinvokeargument name="var_name3" value="value3"/>
</cfinvoke>

<cfset customArr= arrayNew(1)>
<cfloop index="i" from="1" to="5">
<cfscript>
ResponseArr = StructNew( );
ResponseArr.Var1 = ReturnArray[i].Var1;
ResponseArr.Var2 = ReturnArray[i].Var2;
ResponseArr.Var3 = ReturnArray[i].Var3;

customArr[i] = ResponseArr;
</cfscript>
</cfloop>

<cfdump var="#customArr#">
carehart said on Oct 4, 2005 at 1:49 PM :
Folks, the comment of the "syntax 2" example and indeed the first line of the page both suggest that using <cfinvoke method="somefunction"> without a COMPONENT attribute can be used only "within a component". That doesn't recognize that CFFUNCTIONs can exist outside a CFC, and indeed this CFINVOKE syntax can call such a method without regard to CFCs.

As such, the first line ("Invokes a component method from within a ColdFusion page or component") and the syntax 2 comment ("this syntax can invoke a method of a component only from within the component") aren't quite accurate.

The problem exists in the CFMX 7 docs as well, and no one has commented on this there. I don't suppose you want people repeating such observations in both livedocs pages. Is it reasonable for us to hope that comments made here that were offered after CFMX 7's release may still influence future doc updates?
rez405 said on Jan 7, 2006 at 5:31 PM :
Hi guys
The issue with 'Could not generate stub objects for web service invocation. ' seem to be with your Firewall. You need to grant access to the JRun Jar Launcher. I have Zone Alarm and given the right access it works.

It feels good to be back into Coldfusion after three years. Ohh Yes.
grantmr said on Apr 27, 2006 at 7:47 PM :
for all those having the 'Could not generate stub objects...' problems, check out http://www.richarddavies.us/archives/2006/02/enabling_web_se_1.php

he's got the solution
milburgr said on Jul 20, 2006 at 6:11 AM :
The url above is out of service... any chance someone can post the contents of http://www.richarddavies.us/archives/2006/02/enabling_web_se_1.php
?
Thanks,
Greg
Jeff_C said on Sep 5, 2006 at 6:31 AM :
milburgr,

Here is the link you requested http://www.richarddavies.us/archives/2006/02/enabling_web_services.php
browna3 said on Nov 20, 2006 at 4:36 PM :
After spending an hour trying to write an cfinvoke and .cfc for a user login I realized something that might seem obvious to some, but for others it can be quite a pain. You cannot pass USERNAME and PASSWORD as arguments to a cffunction. I found if you change it to usrname and passwd or anything else like that it works fine but otherwise it gives you an error if you require those arguments.
x-ceko said on Feb 13, 2007 at 1:06 PM :
Make sure you are not inheriting Application.cfm from top.
I got the same error and I created blank Application.cfm in the same folder with component and it works fine.
egeis said on Aug 14, 2007 at 12:09 PM :
For anyone having trouble using cfinvoke to call a cfc function....if you have recently updated the cfc function's attributes (e.g. - name, arguments, etc..) you need to restart the ColdFusion service.

I believe this is due to a caching issue with the wsdl file created and stored by ColdFusion.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/tags-p67.htm