User Guide

Table Of Contents
894 Chapter 36: Using Web Services
To access a web service from CFScript:
1.
Create a ColdFusion page with the following content:
<cfscript>
ws = CreateObject("webservice",
"http://www.xmethods.net/sd/2001/TemperatureService.wsdl");
xlatstring = ws.getTemp("55987");
writeoutput(xlatstring);
</cfscript>
2.
Save the page as wscfscript.cfm in your web root directory.
3.
View the page in your browser.
You can also use named parameters to pass information to a web service. The following example
performs the same operation as above, except that it uses named parameters to make the web
service request:
<cfscript>
ws = CreateObject("webservice",
"http://www.xmethods.net/sd/2001/TemperatureService.wsdl");
xlatstring = ws.getTemp(zipcode = "55987");
writeoutput("The temperature at 55987 is " & xlatstring);
</cfscript>
Consuming web services that are not generated by Macromedia
ColdFusion MX
To consume a web service that is implemented in a technology other than ColdFusion MX, the
web service must have one of the following sets of options:
rpc as the SOAP binding style and encoding as the encodingStyle
document as the SOAP binding style and literal as the encodingStyle
The following example shows a portion of the WSDL file for the TemperatureService web service:
<binding name="TemperatureBinding" type="tns:TemperaturePortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/
>
<operation name="getTemp">
<soap:operation soapAction=""/>
<input>
<soap:body use="encoded" namespace="urn:xmethods-Temperature"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="urn:xmethods-Temperature"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
The WSDL file for the TemperatureService web service is compatible with ColdFusion MX
because it uses rpc as the binding style, and encoding as the encodingStyle.