ColdFusion automatically creates a WSDL file for any component referenced as a web service. For example, if you have a component named echo.cfc in your web root directory, you can view its corresponding WSDL file by requesting the component as follows:
http://localhost/echo.cfc?wsdl
For example, you define a ColdFusion component as follows:
<cfcomponent> <cffunction
name = "echoString"
returnType = "string"
output = "no"
access = "remote"> <cfargument name = "input" type = "string"> <cfreturn #arguments.input#> </cffunction> </cfcomponent>
Tip: If you register the component in Dreamweaver MX 2004, it appears in the Components tab of the Application panel.
Requesting the WSDL file in a browser returns the following:
<?xml version="1.0" encoding="UTF-8"?> <wsdl:definitions targetNamespace="http://ws" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://ws" xmlns:intf="http://ws" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns1="http://rpc.xml.coldfusion" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <!--WSDL created by Macromedia ColdFusion MX version 7,0,0,87956--> <wsdl:types> <schema targetNamespace="http://rpc.xml.coldfusion" xmlns="http://www.w3.org/2001/XMLSchema"> <import namespace="http://schemas.xmlsoap.org/soap/encoding/"/> <complexType name="CFCInvocationException"> <sequence/> </complexType> </schema> </wsdl:types> <wsdl:message name="CFCInvocationException"> <wsdl:part name="fault" type="tns1:CFCInvocationException"/> </wsdl:message><wsdl:message name="echoStringResponse">
<wsdl:part name="echoStringReturn" type="xsd:string"/>
</wsdl:message>
<wsdl:message name="echoStringRequest">
<wsdl:part name="input" type="xsd:string"/>
</wsdl:message>
<wsdl:portType name="echo"><wsdl:operation name="echoString" parameterOrder="input">
<wsdl:input message="impl:echoStringRequest" name="echoStringRequest"/>
<wsdl:output message="impl:echoStringResponse"
name="echoStringResponse"/>
<wsdl:fault message="impl:CFCInvocationException" name="CFCInvocationException"/> </wsdl:operation> </wsdl:portType> <wsdl:binding name="echo.cfcSoapBinding" type="impl:echo"> <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/ http"/> <wsdl:operation name="echoString"> <wsdlsoap:operation soapAction=""/><wsdl:input name="echoStringRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/ encoding/" namespace="http://ws" use="encoded"/> </wsdl:input><wsdl:output name="echoStringResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/ encoding/" namespace="http://ws" use="encoded"/> </wsdl:output> <wsdl:fault name="CFCInvocationException"> <wsdlsoap:fault encodingStyle="http://schemas.xmlsoap.org/soap/ encoding/" name="CFCInvocationException" namespace= "http://ws" use="encoded"/> </wsdl:fault> </wsdl:operation> </wsdl:binding> <wsdl:service name="echoService"> <wsdl:port binding="impl:echo.cfcSoapBinding" name="echo.cfc"> <wsdlsoap:address location="http://localhost:8500/ws/echo.cfc"/> </wsdl:port> </wsdl:service> </wsdl:definitions>
<cfcomponent output="false"> <cffunction
name = "echoString"
returnType = "string"
output = "no"
access = "remote"> <cfargument name = "input" type = "string"> <cfreturn #arguments.input#> </cffunction> </cfcomponent>
<cfinvoke webservice ="http://localhost/echo.cfc?wsdl" method ="echoString" input = "hello" returnVariable="foo"> <cfoutput>#foo#</cfoutput>
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>