User Guide

Table Of Contents
892 Chapter 36: Using Web Services
Handling return values from a web service
Web service operations often return information back to your application. You can determine the
name and data type of returned information by examining subelements of the message and
operation elements in the WSDL file.
The following example shows a portion of the WSDL file for the TemperatureService web service:
<message name="getTempRequest">
<part name="zipcode" type="xsd:string"/>
</message>
<message name="getTempResponse">
<part name="return" type="xsd:float"/>
</message>
<portType name="TemperaturePortType">
<operation name="getTemp">
<input message="tns:getTempRequest"/>
<output message="tns:getTempResponse"/>
</operation>
</portType>
The operation getTemp returns a message of type getTempResponse. The message statement in
the WSDL file defines the getTempResponse message as containing a single string parameter
named
return.
Using cfinvoke to consume a web service
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
cfinvoke syntax, see CFML
Reference.
Note: You can pass parameters to a web service using the cfinvokeargument tag or by specifying
parameter names in the
cfinvoke tag itself. For more information, see “Passing parameters to
methods using the cfinvoke tag” on page 225.
To access a web service using cfinvoke:
1.
Create a ColdFusion page with the following content:
<cfinvoke
webservice="http://www.xmethods.net/sd/2001/TemperatureService.wsdl"
method="getTemp"
returnvariable="aTemp">
<cfinvokeargument name="zipcode" value="55987"/>
</cfinvoke>
<cfoutput>The temperature at zip code 55987 is #aTemp#</cfoutput>
2.
Save the page as wscfc.cfm in your web root directory.
3.
View the page in your browser.