Accessibility

Table of Contents

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

Adding More Complex Functionality

Obviously you will want to create more sophisticated web services that offer more than string literals. Now you will add a function to the CFC that returns query data.

Exercise 3

  1. Open Simple.cfc from C:\CFusionMX\devnet\ws.
  2. Add another function to the CFC with the following attributes:

    • name="returnquery"
    • access="remote"
    • returntype="query"
  3. As a best practice, create a variable local to the function using the cfset tag:

    <cfset var qBikeParts="">

  4. Now add the following query to retrieve bike part information from the database:
    <cfquery name="qBikeParts" datasource="devnetws">
    SELECT name, description, price
    FROM Parts
    ORDER BY name 
    </cfquery>
    
  5. Return the query using a cfreturn tag:

    <cfreturn qBikeParts>

  6. Ensure your new function appears as follows:

    <cffunction name="returnquery" access="remote" returntype="query">
    		<cfset var qBikeParts="">
    		<cfquery name="qBikeParts" datasource="devnetws">
    			SELECT name, description, price
    			FROM Parts
    			ORDER BY name 
    		</cfquery>
    		<cfreturn qBikeParts>
    	</cffunction>
    
  7. Save the document.
  8. Browse the CFC with the ?wsdl parameter appended to the URL as follows: http://127.0.0.1:8500/devnet/ws/Simple.cfc?wsdl to ensure you are not receiving any errors.