User Guide

Table Of Contents
Consuming web services 893
You can omit a parameter by setting the cfinvokeargument omit attribute to "yes". If the
WSDL specifies that the argument is nillable, ColdFusion MX sets the associated argument to
null. If the WSDL specifies minoccurs=0, ColdFusion MX 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.
Using CFScript to consume a web service
The example in this section uses CFScript to consume a web service. In CFScript, you use the
CreateObject function to connect to the web service. After connecting, you can make requests
to the service. For
CreateObject syntax, see CFML Reference.
After creating the web service object, you can call operations of the web service using dot
notation, in the following form:
webServiceName.operationName(inputVal1, inputVal2, ... )
You can handle return values from web services by writing them to a variable, as the following
example shows:
resultVar = webServiceName.operationName(inputVal1, inputVal2, ... );
Or, you can pass the return values directly to a function, such as the WriteOutput function, as
the following example shows:
writeoutput(webServiceName.operationName(inputVal1, inputVal2, ...) );