Adobe
Products
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
Student and Teacher Editions
More products
Solutions
Creative tools for business
Digital marketing
Digital media
Education
Financial services
Government
Web Experience Management
More solutions
Learning Help Downloads Company
Buy
Home use for personal and home office
Education for students, educators, and staff
Business for small and medium businesses
Licensing programs for businesses, schools, and government
Special offers
Search
 
Info Sign in
Welcome,
My cart
My orders My Adobe
My Adobe
My orders
My information
My preferences
My products and services
Sign out
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out My orders My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Review and Checkout
Adobe Developer Connection / Dreamweaver Developer Center /

Creating and consuming ColdFusion components and web services with Dreamweaver CS4

by Raymond Camden

Raymond Camden
  • raymondcamden.com

Content

  • Creating a simple CFC through Code view
  • Using your CFC
  • Passing variables to a CFC
  • Consuming a web service

Created

22 December 2008

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
application ColdFusion 8 Dreamweaver CS4 extensibility web services

Requirements

Prerequisite knowledge

Familiarity with Dreamweaver and ColdFusion.

User level

Intermediate

Required products

  • Dreamweaver (Download trial)
  • ColdFusion (Download trial)

Sample files

  • creating_cfcs.zip (ZIP, 4K) (3 KB)

Note: This is an updated version of an article written in 2002 by Matt Brown.

Adobe ColdFusion 8 has numerous features that can help you create more powerful Internet applications than you ever have before. Among the most important capabilities made possible by these features are the ability to create components and the ability to consume web services. ColdFusion components (CFCs) are ColdFusion files that encapsulate application functionality and make that functionality available to browsers, other applications, Adobe Flash Players, and web services. They provide a simple and flexible way to maintain and reuse your code as you work, and they separate the logic from your pages. Adobe Dreamweaver CS4 makes it easy to create and consume components and web services using ColdFusion 8.

In this tutorial, you'll learn how to create simple ColdFusion components through manual coding in the Dreamweaver CS4 Code view and through the Dreamweaver CS4 Create Components dialog box. I'll show you how to consume the CFCs and how to consume a web service.

Web services are similar to CFCs in that they are applications into which you feed data and then receive some information. They allow you to add functionality to your site without having to create the back end for those pieces of your application. For example, if you were creating an online store and needed instant currency conversions, you could use web services. Or, you may want to be able to tell visitors how far they are from your location. Or, you may want to be able to access the Federal Express package tracking system. There are a wide variety of services available on the web that your applications can consume through ColdFusion 8.

Note: Due to the simple nature of the example CFC described in this article, and the introductory nature of the article itself, the example CFC does not use the var scope. The var scope prevents variables within CFC methods from leaking out and causing possible bugs. For more details on the var scope, see Creating user-defined functions.

Creating a simple CFC through Code view

The simplest form of a CFC is some ColdFusion code that you have abstracted to a separate ColdFusion page and can invoke from other ColdFusion pages. One basic application is to create the footer or copyright information for a particular site. You could do this same thing a number of ways in ColdFusion without CFCs, as developers have done in the past, but this is a basic example of a way to apply CFCs.

To start creating a CFC, follow these steps:

  1. Create a folder named myCFC in your ColdFusion 8 web root. You can either put the CFC and ColdFusion pages in a separate folder, like an asset, or in the same folder as the group of CFML pages that use the CFC. Regardless, Dreamweaver CS4 will locate them and make all CFCs in your defined site available to all other CFML pages in the website. You can store CFCs anywhere in your web root, but it is a best practice to keep them in a separate folder.
  2. Open Dreamweaver CS4 and choose File > New.
  3. In the New Document dialog box, select ColdFusion component as the Page Type. Click Create.
  4. Choose File > Save. Save the CFC in the myCFC folder with the name TestCFC.cfc. Note that the file extension is CFC and not CFM.

In Dreamweaver, view the code. (You may need to click Show Code View.)

Because you selected ColdFusion component when you chose the type of file to create, the CFC you created has the following code:

<cfcomponent> <cffunction name="myFunction" access="public" returntype="string"> <cfargument name="myArgument" type="string" required="yes"> <cfset myResult="foo"> <cfreturn myResult> </cffunction> </cfcomponent>

This is simply one large nested tag in a file with nothing else in it, but CFCs are much more. They can provide web services and can be used in any of your ColdFusion 8 and Adobe Flash applications. (For examples on how to use CFCs with Adobe Flash and Flash Remoting visit the ColdFusion 8 Developer Center.)

The cfcomponent tag denotes the CFC much like the HTML tag indicates the beginning and end of an HTML page.

The cffunction tag indicates the functionality of the component. There can be multiple cffunction tags in a single component. When you invoke the CFC from your ColdFusion page, you can call any one of the functions. This is especially useful if you have sets of related functionality that you want to move to a separate file to improve code maintainability. Inside the cffunction tag, you can process as much ColdFusion code as you like.

The cffunction tag has multiple attributes. Dreamweaver CS4 inserts three attributes by default:

  • name: The name of the function needs to be unique in the CFC page so that you can call each function individually. As with JavaScript functions, there should be no spaces in the name.
  • access: This determines who can access the component method by client type. Leave the access set to public, which means that any other CFML page on the ColdFusion server can access the CFC.
  • returntype: This attribute gives data type validation for returned values. Leave this attribute in your code.

Note: For more information on the cffunction tag in CFCs, refer to the CFML documentation installed with ColdFusion 8.

By default, when you create a CFC in Dreamweaver CS4, it adds the cfargument tag, sets a result, and returns the result in a variable.

The cfargument tag informs the function that the CFML page calling the function is passing information to it. This example will not use the cfargument tag, so you can delete it for now. I'll talk about how to use it in the next example. Within the cffunction tag, you will use the cfset tag to create a variable or variables that will hold the function result.

The following example creates a date for the CFC to return to the calling CFML page. To create it:

  1. Open TestCFC.cfc if it is not already open in Dreamweaver CS4.
  2. Change the cffunction name attribute to myDateFunction:
<cffunction name="myDateFunction">
  1. Place your cursor before the following line:
<cfset myResult="foo">
  1. Press the Enter key to insert a line.
  2. Create a cfset tag with a variable named mydate that creates a date, as follows:
<cfset mydate = now()>
  1. Format the date created with the mydate variable in the previous step. Change the cfset for the variable myResult, so that it uses the dateformat() function to format the date.

In short, edit the following line:

<cfset myResult="foo">

Change it to:

<cfset myResult = DateFormat(mydate, "mmm-dd-yyyy")>

Your function should now be coded as follows:

<cffunction name="myDateFunction" returntype="string"> <cfset mydate = now()> <cfset myResult = DateFormat(mydate, "mmm-dd-yyyy")> <cfreturn myResult> </cffunction>
  1. Save the TestCFC.cfc file.

You could test this CFC now, but before you do, add another function to the CFC. By doing this, you can call either or both functions from the ColdFusion calling page:

  1. After the closing cffunction tag, press the Enter key to insert a new line.
  2. Start typing <cffunction>. As you type the tag, Dreamweaver's auto-complete feature displays tags for you to choose from. When you have typed <cffun you can see that the auto-complete feature selects the <cffunction> tag. Press the Enter key to select the cffunction tag and display it as code on your page.
  3. Note that the cffunction tag is not complete. There is no closing bracket for it. This indicates that attributes are missing. Press the spacebar in the cffunction tag, and note that Tag Insight displays multiple attribute choices appropriate for the cffunction tag. You can press the Down Arrow key to select an attribute to enter for the tag. In this case, select the name attribute and press the Enter key. Note that the name="" attribute has been inserted in the cffunction tag, and your cursor is located between the quotes for the name attribute value.
  4. Type myTextFunction as the name of your new function, and place your cursor after the closing quotation.
  5. Press the spacebar and select the returntype attribute from the attribute list. Press the Enter key and insert the returntype attribute into the cffunction tag. Note that your cursor is located between the quotes for the returntype attribute value. Select string for the returntype attribute value.
  6. Type a closing bracket (>) to close the cffunction tag. This will close the opening cffunction tag, and insert a closing </cffunction> tag.
  7. Place your cursor between the <cffunction> and </cffunction> tags to enter your new function. Press the Enter key several times to create blank lines.
  8. In the blank lines, type the following:
<b>The date is: </b>
  1. Press return. Your function should look like the following snippet:
<cffunction name="myTextFunction" returntype="string"> <b>The date is: </b> </cffunction>
  1. Save your TestCFC.cfc file.

Using your CFC

Now that you have created a simple CFC with two functions, you are ready to use it. Calling a CFC is easy. In the ColdFusion page where you want to call the CFC, use the cfinvoke tag. In the cfinvoke tag, you can call individual functions inside of the CFC, and you can specify the name of the return variable that is returned from the CFC.

  1. Ensure that you have a ColdFusion site defined in Dreamweaver CS4 on your machine.

    Note: For more details on how to set up a site in Dreamweaver, see Setting up a Dreamweaver site in Dreamweaver Help.

  2. Create a new CFML page in Dreamweaver CS4. Select File > New. Select ColdFusion in the page type column.
  3. Save your file as Test.cfm.
  4. If you are not in Code view, switch to it. Note that you could insert CFCs into your page in Design view, but the code will not be displayed visually. This makes it difficult to call the CFC within your CFML code. It is preferable to create your CFC in Code view.
  5. Choose Window > Components (or press Ctrl+F7). Alternatively, click the component tab in the palette if it is visible in your workspace already (see Figure 1).
  6. If you don't see any components listed, click the Refresh button and the components will appear.
ColdFusion components in Dreamweaver CS4
Figure 1. ColdFusion components in Dreamweaver CS4
  1. Under the entry for TestCFC, there are two functions. The first function, myDateFunction(), returns the date. The second function, myTextFunction(), prints "The date is: ".
  2. Select myTextFunction(), and click the Insert button to insert a call to this function in your ColdFusion Page.
  3. You should see code that looks like this:
<cfinvoke component="myCFC.TestCFC" method="myTextFunction" returnvariable="myTextFunctionRet"> </cfinvoke>
  1. Save your page and press F12 to preview your page in the browser.
  2. The following displays in your browser, "The date is: "

When "The date is:" is displayed in your browser, you have successfully called a CFC from your page. You have called some content that does not reside in the calling page. This is simple because the information is in a separate file. When the test.cfm page is processed, the ColdFusion Application Server processes the myTextFunction() function in TestCFC.cfc and inserts it in the calling page (test.cfm), where the <cfinvoke> tag is located.

The other function in TestCFC, myDateFunction(), requires a little more work to display because it returns a value. This is the most common sort of CFC. Typically you will want to invoke your CFC, access the result, and present the information on your calling page. To do this, follow these steps:

  1. Open the test.cfm page in Dreamweaver CS4.
  2. Switch to Code view.
  3. Enter a few blank lines after the closing cfinvoke tag.
  4. In the Dreamweaver Components Palette, click the Refresh button. Select myDateFunction() from the TestCFC in the Components panel and click Insert.
  5. The following code appears in test.cfm:
<cfinvoke component="myCFC.TestCFC" method="myDateFunction" returnvariable="myDateFunctionRet" > </cfinvoke>
  1. Note that the myDateFunction() function has an attribute named returnvariable. The returnvariable stores the result of the function. The previous function didn't actually return a result, but simply printed its output directly within the call. In this example, however, the result will be stored in a variable called myDateFunctionRet.
  2. In Code view, insert a few blank lines after the second </cfinvoke> tag, and type the following line:
<cfoutput>#myDateFunctionRet#</cfoutput>
  1. Verify that the whole file looks like the following:
<html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <cfinvoke component="myCFC.TestCFC" method="myTextFunction" returnvariable="myTextFunctionRet" > </cfinvoke> <cfinvoke component="myCFC.TestCFC" method="myDateFunction" returnvariable="myDateFunctionRet" > </cfinvoke> <cfoutput>#myDateFunctionRet#</cfoutput> </body> </html>
  1. Save the page and press F12 to preview your page in the browser. Your browser should display "The date is:" followed by the current date; for example, The date is: Oct-21-2008.

Passing variables to a CFC

Now that you have created a simple CFC, you may want to create a CFC that provides a more functionality. In this example, you'll build a CFC that finds an employee and lists the results a few different ways. This CFC will enable you to offer find and search capabilities on any number of pages, but maintain the code in only one place. If you need to change the code later, you only need to change it once, rather than on numerous ColdFusion pages. Additionally, you can access the functionality from other clients, such as Adobe Flash Player, through Adobe Flash Remoting.

In the previous steps, you manually created a CFC. This time, you'll create them using the new Components and Web Services interface in Dreamweaver CS4.

Create the CFC in Dreamweaver CS4

To create the CF follow these steps:

  1. In Dreamweaver CS4 ensure that you are in the ColdFusion 8 web root Site Definition.
  2. Click the Components tab. If you can't see the Components tab, choose Window > Components.
  3. In the Components tab, click the plus (+) icon to create a new CFC through the Create Component dialog box.
    • In the dialog box, for the Display Name, type FindArtist. This is the component name that you'll reference when you call the CFC.
    • In the Name field, type FindArtist. This will be the name of the file in the file system.
    • For the Component directory, select the myCFC directory. It isn't necessary to keep all components in one place, since both Dreamweaver CS4 and ColdFusion 8 search for all the components in your site and make those available to you when you author anything in a ColdFusion site. However, it is a best practice to keep them all in the same place.

    Your screen should display the entries shown in Figure 2.

Creating a CFC.
Figure 2. Creating a CFC.

Note: The Component directory location will be different based on where you created your myCFC folder.

Leave the other fields empty. For more information on these fields, refer to the ColdFusion 8 documentation.

  1. Click Functions under the Section area. From the Function view, click the plus (+) icon to add a function.
  2. For the function name, type FindArtistSort. Select remote for the Access option, and select query for the Return Type (see Figure 3). You can select one of several return types depending on what you wish to return to the calling CFML page.
The Create Component dialog box.
Figure 3. The Create Component dialog box.
  1. Click OK.

Dreamweaver CS4 creates the necessary framework for the CFC:

<!--- Generated by Adobe Dreamweaver CS4 10.0.0.4117 [en] (MacPPC) - Wed Oct 22 2008 13:45:10 GMT-0500 (CDT) ---> <cfcomponent displayName="FindArtist"> <cffunction name="FindArtistSort" access="remote" returnType="query" output="false"> <!--- FindArtistSort body ---> <cfreturn > </cffunction> </cfcomponent>

Now you're ready to add code to the function to make it do something. In this case, you'll create a query that you can access in a few different ways. First, you'll retrieve artist information from the database and sort it. Second, you'll create a function to search for an artist by name. By using a CFC, you can call the query from any ColdFusion pages or application on your ColdFusion server. You can even add more features to the query over time, if necessary.

  1. Open FindArtist.cfc in Code view in Dreamweaver CS4.
  2. Enter a few blank lines after the opening cffunction tag.
  3. Enter the following code on the blank lines:
<cfargument name="lastname" type="string" required="false"> <cfquery name="artistQuery" datasource="cfartgallery"> SELECT * FROM Artists <cfif IsDefined('arguments.LastName')> WHERE LastName LIKE '%#arguments.LastName#%' </cfif> ORDER BY LastName ASC </cfquery>

This query selects all of the information in the Artists table from the cfartgallery data source. The cfartgallery data source is part of the example applications that were installed with your copy of ColdFusion 8. The query checks whether an argument called LastName was passed into the method from the referring page.

If the referring page passed the LastName argument, the query uses the WHERE clause. The WHERE clause filters the query results, returning any last name that matches a combination of letters passed in the arguments.LastName variable. If the referring page does not pass LastName, the query returns a recordset for all the artists, sorted in ascending order by their last name.

  1. Now you'll specify what the CFC returns to your ColdFusion page. Modify the cfreturn tag after the query and before the closing cffunction tag to:
<cfreturn artistQuery />

The cfreturn tag will return the artistQuery so that you can loop through the returned data, as if the query were on a regular ColdFusion page.

  1. Your FindArtist.cfc should look like this:
<!--- Generated by Adobe Dreamweaver CS4 10.0.0.4117 [en] (MacPPC) - Wed Oct 22 2008 13:45:10 GMT-0500 (CDT) ---> <cfcomponent displayName="FindArtist"> <cffunction name="FindArtistSort" access="remote" returnType="query" output="false"> <cfargument name="lastname" type="string" required="false"> <cfquery name="artistQuery" datasource="cfartgallery"> SELECT * FROM Artists <cfif IsDefined('arguments.LastName')> WHERE LastName LIKE '%#arguments.LastName#%' </cfif> ORDER BY LastName ASC </cfquery> <cfreturn artistQuery> </cffunction> </cfcomponent>
  1. Save FindArtist.cfc.

Test your CFC

To test the CFC, create an HTML form and a CFML action page. Your CFML action page will call the CFC.

Create an HTML form where the user will enter search criteria (in this case, just a last name). To do this, create a file named artistname1.cfm and save it in your ColdFusion web root. The file should have the following code:

<html> <head> <title>artistname1</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <!---First form: This form submits the end-user's search criteria---> <form name="form1" method="post" action="artistname2.cfm"> <p>Search for artist: <input type="text" name="LastName"> </p> <p> <input type="submit" name="Submit" value="Submit"> </p> </form> <!---Second form: This form submits no search criteria---> <form name="form2" method="post" action="artistname2.cfm"> <p>Return all artists: <input type="submit" name="Submit2" value="Submit"></p> </form> </body> </html>

Now that you have created a form that passes information to your CFML action page (and your CFC), you'll create the action page that invokes the CFC and displays the result.

  1. Choose File > New. In the New Document dialog box, select ColdFusion from the Page Type column and click Create.
  2. Save the file to the ColdFusion 8 web root. Name the file artistname2.cfm.
  3. From the Components palette, click Refresh and find the FindArtist.cfc you created. Click the CFC to expand its functions.
  4. Click the FindArtistSort function and drag it into the body of your artistname2.cfm file.

    Your page should look like the following:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <cfinvoke component="mycfc.FindArtist" method="FindArtistSort" returnvariable="FindArtistSortRet"> </cfinvoke> </body> </html>
  1. Save artistname2.cfm.

    Now, you have a page that calls the CFC, and the CFC works, but you'll need to add code to display the results that are returned. Add the code in Design view or Code view, whichever you prefer. For this example, I prefer to add the changes in Code view.

  2. Insert a few blank lines after the closing cfinvoke tag and add the following code:
<cfoutput query="FindArtistSortRet">#FirstName# #LastName#<br></cfoutput>
  1. Save artistname2.cfm

Test your application

Now you have a small ColdFusion application and you are ready to test it. Browse to http://localhost:8500/artistname1.cfm (change this URL based on the port number where you're running ColdFusion 8, and where your file, artistname1.cfm, is located in your ColdFusion 8 web root).

Figure 4 shows the form displayed in your browser.

The artist search form.
Figure 4. The artist search form.

Click the Submit button next to Return all artists. The action page displays an entire list of people from the database. Type al in the form field, and click the first Submit button. Notice that the action page still displays all the artists. Why? Your CFC method was built to accept the LastName argument, but the code never actually passed it. Modify the code to look for, and pass, the form value if it exists.

  1. Open artistname2.cfm.
  2. Before the cfinvoke tag, add this code:
<cfif isDefined("form.lastname")>
  1. Modify the cfinvoke tag to pass in the lastname value:
<cfinvoke component="mycfc.FindArtist" method="FindArtistSort" lastname="#form.lastname#" returnvariable="FindArtistSortRet"> </cfinvoke>
  1. Add a cfelse tag after the cfinvoke.
  2. You can now drag the FindArtistSort from the CFC in the components panel. Or you can cut and paste the cfinvoke tag above, but remove the lastname argument.
  3. Your completed code should look like this:
<cfif isDefined("form.lastname")> <cfinvoke component="mycfc.FindArtist" method="FindArtistSort" lastname="#form.lastname#" returnvariable="FindArtistSortRet"> </cfinvoke> <cfelse> <cfinvoke component="mycfc.FindArtist" method="FindArtistSort" returnvariable="FindArtistSortRet"> </cfinvoke> </cfif> <cfoutput query="FindArtistSortRet">#FirstName# #LastName#<br></cfoutput>
  1. Save your file and test the page again. Now the results will be filtered correctly if you enter a value in the input text field.

This one CFC allows you to get as many different result sets as you like. The advantage is that you can keep all of your database logic in one place in your application and not on each individual ColdFusion page.

Consuming a web service

Web services are similar to CFCs in that they are encapsulated functionality that you can access in your website. For this example, you'll create a weather information component that you can use in your pages without having to create the code or maintain it by getting separate daily temperatures for dozens of zip codes. Simply create a form and pass the variables to a web service, and then use the cfoutput tag to insert the returned values into your page.

Before you start, ensure that you have a live connection to the web. This is necessary to consume a remote web service.

Note: This section makes use of a Dreamweaver CS4 feature that is only available on Windows machines. You will not be able to introspect a web service on a Mac OS X machine. You can, of course, still use ColdFusion on Mac OS X and run code that makes use of web services. You just can't use the built-in Dreamweaver's tool to examine the web service.

  1. Create a new ColdFusion document and save it as weathercalculator.cfm in your ColdFusion 8 web root.
  2. Ensure that the Component Palette is visible in Dreamweaver CS4.
  3. In the Component tab, select Web Services from the context menu. This panel lists all of the web services to which you have subscribed, and can therefore insert.
  4. To subscribe to a web service, click the plus (+) button. In the Add Using WSDL dialog box, set the Proxy Generator to ColdFusion MX if it is not already selected. Click the globe icon and select xMethods from the context menu (see Figure 5).
Adding a web service using WSDL.
Figure 5. Adding a web service using WSDL.
  1. This opens the xMethods website. At the xMethods website, you can choose from many services. For this example, select CDYNE Weather - FREE from xmethods.net.

    When you click the link in the list, it displays the service's details and instructions on using it. For this example, look for the WSDL URL, which is highlighted in yellow. (If you have trouble finding it, use the URL in Step 6.)

  2. The following URL is listed at the end of the WSDL line on the page in yellow highlighting:
http://ws.cdyne.com/WeatherWS/Weather.asmx?wsdl

Copy and paste it into the WSDL dialog box as the URL of the WSDL file. ColdFusion uses this URL to access the web service.

  1. Click OK. This adds the new web service to the Components Palette.
  2. Click the getCityWeatherByZIP entry and drag it to the body of your page.
  3. Your file should look like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <cfinvoke webservice="http://ws.cdyne.com/WeatherWS/Weather.asmx?wsdl" method="getCityWeatherByZIP" returnvariable="aWeatherReturn"> <cfinvokeargument name="ZIP" value="enter_value_here"/> </cfinvoke> </body> </html>
  1. Save weathercalculator.cfm.

Now that you have invoked the service, you need to pass a value for the cfinvokeargument tag, so the service has the zip code it needs to get weather information. You also need to display the temperature in the ColdFusion page.

  1. In weathercalculator.cfm, switch to Code view. In the first cfinvokeargument tag, replace "enter_value_here" with #zip#. This passes the zip code that you're going to pass from the form calling this page on to the web service.
  2. Enter a few blank lines after the closing cfinvoke tag and type the following:
<cfoutput>The temperature for #zip# is #aWeatherReturn.temperature#</cfoutput>
  1. Your page should look like the following:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <cfinvoke webservice="http://ws.cdyne.com/WeatherWS/Weather.asmx?wsdl" method="getCityWeatherByZIP" returnvariable="aWeatherReturn"> <cfinvokeargument name="ZIP" value="#zip#"/> </cfinvoke> <cfoutput>The temperature for #zip# is #aWeatherReturn.temperature#</cfoutput> </body> </html>
  1. The temperature value is returned as part of a structure of other information in the web service. You can expand the structs/WeatherReturn node for more details.
  2. Save weathercalculator.cfm.

You have the page that references the web service and displays the return results. Now, create an HTML form that calls weathercalculator.cfm. Ensure that your field names in the HTML form match the value in the cfinvokeargument tag. Additionally, set the form action to post to weathercalculator.cfm. Your HTML form should have the following code:

<html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <form name="form1" method="post" action="weathercalculator.cfm"> <p>Zip: <input type="text" name="zip"> </p> <p> <input type="submit" name="Submit" value="Submit"> </p> </form> </body> </html>

Access your form from a browser. For the zip type 70508 (or your own zip code). Click Submit. Your form passes the value for zip to weathercalculator.cfm, which in turn invokes the web service using the form data. The web service processes and returns a structure in the variable aWeatherReturn. Weathercalculator.cfm displays the zip and the temperature.

Where to from here

You can get much more information about CFCs on the Adobe Developer Connection. Additionally, the ColdFusion 8 documentation, which is installed by default, also has information to help you get started with developing ColdFusion 8 applications.

For more information on web services, there are hundreds of resources. Some of my favorite resources include the following sites:

  • XMethods (Lists many publicly available web services.)
  • IBM web services (Requires free registration.)
  • Microsoft web services (Has a list of UDDI services and resources.)
  • www.webservices.org (Great resource for web services information and tutorials.)

Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License

More Like This

  • Managing multiple subscriptions in PHP
  • Creating user-defined functions for ColdFusion 8 in Dreamweaver CS4
  • Creating a ColdFusion upload page in Dreamweaver CS4
  • Creating custom server behaviors and Dreamweaver extensions
  • XML overview
  • Developing HTML5 games with Impact JavaScript game engine and Dreamweaver CS5.5
  • XSL overview
  • Packaging web apps as mobile apps using PhoneGap and Dreamweaver

Tutorials and samples

Tutorials

  • Understanding HTML5 semantics: Changed and absent elements
  • Mobile app with PhoneGap: Submitting to the Apple App Store
  • PhoneGap and Dreamweaver: Releasing on iOS
  • Mobile app with PhoneGap: Submitting to Android Market

Samples

  • Responsive design with jQuery marquee
  • Customizable starter design for jQuery Mobile
  • Customizable starter design for HTML5 video
  • Customizable starter design for multiscreen development

Dreamweaver user forum

More
04/23/2012 Resolution/Compatibility/liquid layout
04/20/2012 using local/testing server with cs5 inserting images look fine in the split screen but do not show
04/18/2012 Ap Div help
04/23/2012 Updating

Dreamweaver Cookbook

More
11/07/2011 Simple social networking share buttons
09/20/2011 Registration form that will generate email for registrant to validate
08/21/2011 Spry Accordion - Vertical Text - Auto Start on Page Load - Mouse Over Pause
08/17/2011 Using cfdump anywhere you like

Products

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • Mobile Apps
  • Photoshop
  • Touch Apps
  • Student and Teacher Editions

Solutions

  • Digital marketing
  • Digital media
  • Web Experience Management

Industries

  • Education
  • Financial services
  • Government

Help

  • Product help centers
  • Orders and returns
  • Downloading and installing
  • My Adobe

Learning

  • Adobe Developer Connection
  • Adobe TV
  • Training and certification
  • Forums
  • Design Center

Ways to buy

  • For personal and home office
  • For students, educators, and staff
  • For small and medium businesses
  • For businesses, schools, and government
  • Special offers

Downloads

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy Policy and Cookies (Updated)

Ad Choices

Reviewed by TRUSTe: site privacy statement