Using Coldfusion Components To Define Data Types For Web Services - MACROMEDIA COLDFUSION MX 61-DEVELOPING COLDFUSION MX Develop Manual

Developing coldfusion mx applications
Table of Contents

Advertisement

<cfreturn #arguments.input#>
</cffunction>
</cfcomponent>
Save this file as echo.cfc in your web root directory.
2
Create a ColdFusion page with the following content:
3
<cfinvoke webservice ="http://localhost/echo.cfc?wsdl"
method ="echoString"
input = "hello"
returnVariable="foo">
<cfoutput>#foo#</cfoutput>
Save this file as echoclient.cfm in your web root directory.
4
Request echoclient.cfm in your browser.
5
The following string appears in your browser:
hello
You can also invoke the web service using the following code:
<cfscript>
ws = CreateObject("webservice", "http://localhost/echo.cfc?wsdl");
wsresults = ws.echoString("hello");
writeoutput(wsresults);
</cfscript>

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#>
724
Chapter 32: Using Web Services

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the COLDFUSION MX 61-DEVELOPING COLDFUSION MX and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel

This manual is also suitable for:

Coldfusion mx

Table of Contents