Contents > Developing ColdFusion MX Applications > Using Web Services > Publishing web services > Using ColdFusion components to define data types for web services PreviousNext

Using ColdFusion components to define data types for web services

ColdFusion components let you define both methods and properties of the component. Once defined, you can use components to define data types for web services. The following code defines a component in the file address.cfc:

<cfcomponent>
   <cfproperty name="Number" type="numeric">
   <cfproperty name="Street" type="string">
   <cfproperty name="City" type="string">
   <cfproperty name="State" type="string">
   <cfproperty name="Country" type="string">
</cfcomponent>

This component contains properties that represent a street address. The following code defines a component in the file name.cfc that defines first and last name properties:

<cfcomponent>
   <cfproperty name="Firstname" type="string">
   <cfproperty name="Lastname" type="string">
</cfcomponent>

You can then use address and name to define data types in a ColdFusion component created to publish a web service, as the following example shows:

<cfcomponent>
   <cffunction name="echoName" returnType="name" access="remote">
         <cfargument name="input" type="name">
         <cfreturn #arguments.input#>
   </cffunction>

   <cffunction name="echoAddress" returnType="address" access="remote">
         <cfargument name="input" type="address">
         <cfreturn #arguments.input#>
   </cffunction>
</cfcomponent>

Note: If the component files are not in a directory under your web root, you must create a ColdFusion mapping to the directory containing them.

If you register the component in Dreamweaver MX, it appears in the Components tab of the Application panel, as the following figure shows:

This is a picture of the feature being described.

The WSDL file for the web service contains data definitions for the complex types name and address. Each definition consists of the elements that define the type as specified in the ColdFusion component file for that type. For example, shown below is the definition for name:

<complexType name="name"> 
   <all> 
      <element name="Firstname" nillable="true" type="xsd:string" /> 
      <element name="Lastname" nillable="true" type="xsd:string" /> 
   </all> 
</complexType>

Contents > Developing ColdFusion MX Applications > Using Web Services > Publishing web services > Using ColdFusion components to define data types for web services 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.