Accessibility

Table of Contents

A Beginner's Guide to Creating and Consuming Web Services with ColdFusion and Flash

Consuming Web Services with ColdFusion

When consuming a web service with ColdFusion (any web service, not just those written in ColdFusion), you can use the cfinvoke tag. To do this you must supply the following information as attributes:

  • webservice: The URL of the web service.
  • method: The function name in a CFC, or one of the available methods documented by the web service provider.
  • returnvariable: The name of the variable where you want the returned data, if any, to be stored.

Exercise 4: Using ColdFusion to Consume a Web Service

  1. Create a new document and save it as wsconsumer.cfm in C:\CFusionMX\devnet\ws.
  2. Use a cfinvoke tag with the following attributes:

    • webservice="http://127.0.0.1:8500/devnet/ws/Simple.cfc?wsdl"
    • method="firstws"
    • returnvariable="returnedText"
  3. After the cfinvoke tag, display the data returned using the cfoutput tag and the variable name:

    <cfoutput>
    	#variables.returnedText#
    </cfoutput>
    
  4. Ensure your code appears as follows:
    <cfinvoke 
    webservice="http://127.0.0.1:8500/devnet/ws/Simple.cfc?wsdl"
    method="firstws"
    returnvariable="returnedText">
    </cfinvoke>
    
    <cfoutput>
    	#variables.returnedText#
    </cfoutput>
    
  5. Save the document and browse it. The text, DevNet is great!, displays.
  6. In the same file, use another cfinvoke tag with the following attributes to get the query data that the web service returned:

    • webservice="http://127.0.0.1:8500/devnet/ws/Simple.cfc?wsdl"
    • method="returnquery"
    • returnvariable="returnedQuery"
  7. Display the returned query using the cfdump tag:

    <cfdump var="#returnedQuery#">

  8. Save the document and browse it. In addition to the text, you should output a dump of the query, part of which is shown here:

    The cfdump tag output from the query

    Figure 4. The cfdump tag output from the query

    Note: If you are using Dreamweaver to build your files, and the cfdump tag does not generate output that appears as above, remove the <!DOCTYPE …> tag and the cfdump tag information will display.