Adobe ColdFusion 8

Producing WSDL files

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

The cfcomponent tag includes optional attributes that you can use to control the WSDL that ColdFusion generates. You can use these attributes to create meaningful WSDL attribute names, as the following example shows:

<cfcomponent style="document"     
namespace = "http://www.mycompany.com/"
    serviceportname = "RestrictedEmpInfo"
    porttypename = "RestrictedEmpInfo"
    bindingname = "myns:RestrictedEmpInfo"
    displayname = "RestrictedEmpInfo"
    hint = "RestrictedEmpInfo">

For complete control of the WSDL, advanced users can specify the cfcomponent wsdlFile attribute to use a predefined WSDL file.

The following example defines a ColdFusion component that can be invoked as a web service:

<cfcomponent>
    <cffunction 
    name = "echoString" 
    returnType = "string" 
    output = "no"
    access = "remote">
        <cfargument name = "input" type = "string">
        <cfreturn #arguments.input#>
    </cffunction>
</cfcomponent>

If you register the component in Dreamweaver, 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 ColdFusion -->
<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>

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>