730
Chapter 32: Using Web Services
To call the updateEmployeeInfo operation, you create a ColdFusion structure, initialize six fields
of the structure that correspond to the six elements of Employee, then call the operation, as the
following code shows:
<!--- Create a structure using CFScript, then call the web service. --->
<cfscript>
stUser = structNew();
stUser.active = TRUE;
stUser.fname = "John";
stUser.lname = "Smith";
stUser.age = 23;
stUser.hiredate = createDate(2002,02,22);
stUser.number = 123.321;
ws = createObject("webservice", "http://somehost/echosimple.asmx?wsdl");
ws.echoStruct(stUser);
</cfscript>
You can use structures for passing input parameters as complex types in many situations.
However, to build a structure to model a complex type, you have to inspect the WSDL file for the
web service to determine the layout of the complex type. This can take some practice.
Handling return values as complex types
When a web service returns a complex type, you can write that returned value directly to a
ColdFusion variable.
The previous section used a complex data type named Employee to define an input parameter to
an operation. A WSDL file can also define a return value using the Employee type, as the
following code shows:
<message name="updateEmployeeInfoSoapOut">
<part name="updateEmployeeInfoResult" type="s0:Employee" />
</message>
<operation name="updateEmployeeInfo">
<input message="s0:updateEmployeeInfoSoapIn" />
<output message="s0:updateEmployeeInfoSoapOut" />
</operation>
In this example, the operation updateEmployeeInfo takes a complex type as input and returns a
complex type as output. To handle the input parameter, you create a structure. To handle the
returned value, you write it to a ColdFusion variable, as the following example shows:
<!--- Create a structure using CFScript, then call the web service. --->
<!--- Write the returned value to a ColdFusion variable. --->
<cfscript>
stUser = structNew();
stUser.active = TRUE;
stUser.fname = "John";
stUser.lname = "Smith";
stUser.age = 23;
stUser.hiredate = createDate(2002,02,22);
stUser.number = 123.321;
ws = createObject("webservice", "http://somehost/echosimple.asmx?wsdl");
myReturnVar = ws.echoStruct(stUser);
</cfscript>
Summary of Contents for ColdFusion MX
Page 1: ...Developing ColdFusion MX Applications...
Page 22: ...22 Contents...
Page 38: ......
Page 52: ...52 Chapter 2 Elements of CFML...
Page 162: ......
Page 218: ...218 Chapter 10 Writing and Calling User Defined Functions...
Page 250: ...250 Chapter 11 Building and Using ColdFusion Components...
Page 264: ...264 Chapter 12 Building Custom CFXAPI Tags...
Page 266: ......
Page 314: ...314 Chapter 14 Handling Errors...
Page 344: ...344 Chapter 15 Using Persistent Data and Locking...
Page 349: ...About user security 349...
Page 357: ...Security scenarios 357...
Page 370: ...370 Chapter 16 Securing Applications...
Page 388: ...388 Chapter 17 Developing Globalized Applications...
Page 408: ...408 Chapter 18 Debugging and Troubleshooting Applications...
Page 410: ......
Page 426: ...426 Chapter 19 Introduction to Databases and SQL...
Page 476: ...476 Chapter 22 Using Query of Queries...
Page 534: ...534 Chapter 24 Building a Search Interface...
Page 556: ...556 Chapter 25 Using Verity Search Expressions...
Page 558: ......
Page 582: ...582 Chapter 26 Retrieving and Formatting Data...
Page 668: ......
Page 734: ...734 Chapter 32 Using Web Services...
Page 760: ...760 Chapter 33 Integrating J2EE and Java Elements in CFML Applications...
Page 786: ...786 Chapter 34 Integrating COM and CORBA Objects in CFML Applications...
Page 788: ......