User Guide

Table Of Contents
902 Chapter 36: Using Web Services
</wsdl:service>
</wsdl:definitions>
To publish a web service:
1.
Create a ColdFusion page with the following content:
<cfcomponent output="false">
<cffunction
name = "echoString"
returnType = "string"
output = "no"
access = "remote">
<cfargument name = "input" type = "string">
<cfreturn #arguments.input#>
</cffunction>
</cfcomponent>
2.
Save this file as echo.cfc in your web root directory.
3.
Create a ColdFusion page with the following content:
<cfinvoke webservice ="http://localhost/echo.cfc?wsdl"
method ="echoString"
input = "hello"
returnVariable="foo">
<cfoutput>#foo#</cfoutput>
4.
Save this file as echoclient.cfm in your web root directory.
5.
Request echoclient.cfm in your browser.
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 lets you define components that contain only properties. Once defined, you can use
components to define data types for web services. The following code defines a component in the
file address.cfc that contains properties that represent a street address:
<cfcomponent>
<cfproperty name="AddrNumber" type="numeric">
<cfproperty name="Street" type="string">
<cfproperty name="City" type="string">
<cfproperty name="State" type="string">
<cfproperty name="Country" type="string">
</cfcomponent>