User Guide

Table Of Contents
910 Chapter 36: Using Web Services
Passing input parameters to web services as complex types
A web service can take a complex data type as input. In this situation, you can construct a
ColdFusion structure that models the complex data type, then pass the structure to the web
service.
For example, the following excerpt from a WSDL file shows the definition of a complex type
named Employee:
<s:complexType name="Employee">
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="fname" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="lname" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="active" type="s:boolean" />
<s:element minOccurs="1" maxOccurs="1" name="age" type="s:int" />
<s:element minOccurs="1" maxOccurs="1" name="hiredate" type="s:dateTime" />
<s:element minOccurs="1" maxOccurs="1" name="number" type="s:double" />
</s:sequence>
</s:complexType>
The Employee data type definition includes six elements, the data type of each element, and the
name of each element.
Another excerpt from the WSDL file shows a message definition using the Employee data type.
This message defines an input parameter, as the following code shows:
<message name="updateEmployeeInfoSoapIn">
<part name="thestruct" type="s0:Employee" />
</message>
A third excerpt from the WSDL file shows the definition of an operation, named
updateEmployeeInfo, possibly one that updates the employee database with the employee
information. This operation takes as input a parameter of type Employee, as the following code
shows:
<operation name="updateEmployeeInfo">
<input message="s0:updateEmployeeInfoSoapIn" />
</operation>
To call the updateEmployeeInfo operation, create a ColdFusion structure, initialize six fields of
the structure that correspond to the six elements of Employee, and 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/EmployeeInfo.asmx?wsdl");
ws.updateEmployeeInfo(stUser);
</cfscript>