Adobe COLDFUSION 9 Manual page 1105

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Using Web Elements and External Objects
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 following example uses CFScript to consume a web service. In CFScript, you use the
connect to the web service. After connecting, you can make requests to the service. For
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
shows:
writeoutput(webServiceName.operationName(inputVal1, inputVal2, ...) );
Access a web service from CFScript
Create a ColdFusion page with the following content:
1
<cfscript>
ws = CreateObject("webservice",
"http://www.xmethods.net/sd/2001/TemperatureService.wsdl");
xlatstring = ws.getTemp("55987");
writeoutput(xlatstring);
</cfscript>
Save the page as wscfscript.cfm in your web root directory.
2
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 the preceding code, except that it uses named parameters to make the web service request:
WriteOutput
Last updated 8/5/2010
function to
CreateObject
syntax, see the
CreateObject
function, as the following example
1100

Advertisement

Table of Contents
loading

Table of Contents