Adobe ColdFusion 8

Consuming ColdFusion web services

Your application can consume web services created in ColdFusion. You do not have to perform any special processing on the input parameters or return values because ColdFusion handles data mappings automatically when consuming a ColdFusion web service.

For example, when ColdFusion publishes a web service that returns a query, or takes a query as an input, the WSDL file for that service lists its data type as QueryBean. However, a ColdFusion application consuming this web service can pass a ColdFusion query object to the function as an input, or write a returned QueryBean to a ColdFusion query object.

Note: For a list of how ColdFusion data types map to WSDL data types, see Data conversions between ColdFusion and WSDL data types.

The following example shows a ColdFusion component that takes a query as input and echoes the query back to the caller:

<cfcomponent>
    <cffunction name='echoQuery' returnType='query' access='remote'>
        <cfargument name='input' type='query'>
        <cfreturn #arguments.input#>
    </cffunction>
</cfcomponent>

In the WSDL file for the echotypes.cfc component, you see the following definitions that specify the type of the function's input and output as QueryBean:

<wsdl:message name="echoQueryResponse">
  <wsdl:part name="echoQueryReturn" type="tns1:QueryBean"/>
</wsdl:message>
<wsdl:message name="echoQueryRequest">
  <wsdl:part name="input" type="tns1:QueryBean"/>
</wsdl:message>

For information on displaying WSDL, see Producing WSDL files.

Since ColdFusion automatically handles mappings to ColdFusion data types, you can call this web service as the following example shows:

<head>
<title>Passing queries to web services</title>
</head>
<body>
<cfquery name="GetEmployees" datasource="cfdocexamples">
    SELECT FirstName, LastName, Salary
    FROM Employee
</cfquery>

<cfinvoke 
    webservice = "http://localhost/echotypes.cfc?wsdl"
    method = "echoQuery"
    input="#GetEmployees#"
    returnVariable = "returnedQuery">

<cfoutput>
    Is returned result a query? #isQuery(returnedQuery)# <br><br>
</cfoutput>

<cfoutput query="returnedQuery">
    #FirstName#, #LastName#, #Salary#<br>
</cfoutput>
</body>