This section describes how to consume a web service using the cfinvoke tag. With the cfinvoke tag, you reference the WSDL file and invoke an operation on the web service with a single tag.
The cfinvoke tag includes attributes that specify the URL to the WSDL file, the method to invoke, the return variable, and input parameters. For complete syntax, see the CFML Reference.
Access a web service using cfinvoke
You can omit a parameter by setting the omit attribute to "yes". If the WSDL specifies that the argument is nillable, ColdFusion sets the associated argument to null. If the WSDL specifies minoccurs=0, ColdFusion omits the argument from the WSDL. However, CFC web services must still specify required="true" for all arguments.
You can also use an attribute collection to pass parameters. An attribute collections is a structure where each structure key corresponds to a parameter name and each structure value is the parameter value passed for the corresponding key. The following example shows an invocation of a web service using an attribute collection:
<cfscript> stArgs = structNew(); stArgs.zipcode = "55987"; </cfscript> <cfinvoke webservice="http://www.xmethods.net/sd/2001/TemperatureService.wsdl" method="getTemp" argumentcollection="#stArgs#" returnvariable="aTemp"> <cfoutput>The temperature at zip code 55987 is #aTemp#</cfoutput>
In this example, you create the structure in a CFScript block, but you can use any ColdFusion method to create the structure.