Adobe ColdFusion 8

Specifying data types of function arguments and return values

The cffunction tag lets you define a single return value and one or more input parameters passed to a function. As part of the function definition, you include the data type of the return value and input parameters.

The following example shows a component that defines a function with a return value of type string, one input parameter of type string, and one input parameter of type numeric:

<cfcomponent>
    <cffunction name="trimString" returnType="string" output="no">
        <cfargument name="inString" type="string">
        <cfargument name="trimLength" type="numeric">
    </cffunction>
</cfcomponent>

As part of publishing the component for access as a web service, ColdFusion generates the WSDL file that defines the component where the WSDL file includes definitions for how ColdFusion data types map to WSDL data types. The following table shows this mapping:

ColdFusion data type

WSDL data type published

numeric

SOAP-ENC:double

boolean

SOAP-ENC:boolean

string

SOAP-ENC:string

array

SOAP-ENC:Array

binary

xsd:base64Binary

date

xsd:dateTime

guid

SOAP-ENC:string

uuid

SOAP-ENC:string

void (operation returns nothing)

 

struct

Map

query

QueryBean

any

complex type

component definition

complex type

In most cases, consumers of ColdFusion web services can easily pass data to and return results from component functions by mapping their data types to the WSDL data types shown in the preceding table.

Note: Document-literal web services use XML schema data types, not SOAP-ENC data types. For more information, see Publishing document-literal style web services.

For ColdFusion structures and queries, clients might have to perform some processing to map their data to the correct type. For more information, see Publishing web services that use complex data types.

You can also define a data type in one ColdFusion component based on another component definition. For more information on using components to specify a data type, see Using ColdFusion components to define data types for web services.