Contents > Developing ColdFusion MX Applications > Using Web Services > Handling complex data types > Consuming web services that use complex data types Passing input parameters to web services as complex types PreviousNext

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, 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.


Contents > Developing ColdFusion MX Applications > Using Web Services > Handling complex data types > Consuming web services that use complex data types Passing input parameters to web services as complex types PreviousNext

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.