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>
730
Chapter 32: Using Web Services
Need help?
Do you have a question about the COLDFUSION MX 61-DEVELOPING COLDFUSION MX and is the answer not in the manual?
Questions and answers