Web Services in Dreamweaver MX from ColdFusion MX

Web Services is a fairly new technology that has taken the Web by storm. Basically, a Web service is a component that is created to communicate using standard XML formats to any application that knows how to talk to it. The Web service will have an interface written in Web Service Description Language (WSDL). The interface describes what the Web service does and how to communicate with it. The actual communication is done with XML. Because XML is basically just text, an application that can read text can read and interpret a Web service. Because of this, Web services can be created by one type of server and utilized by anyone who can read the XML.

Some examples of Web services are

  • Stock services Type in a ticker symbol and get a stock quote.
  • Weather service Type in a ZIP code to get local weather.
  • Currency exchange rates Type in "currency from," "currency to," and a value.
  • Language translation Type in a phrase, "language from," and "language to" for a translation.
  • Web search Type in a search word or words and get Web results.

And there are many more too numerous to mention. Web services, in short, can offer anything that has a question and an answer, call and response, or a simple information service. ColdFusion MX has made working with Web services even easier by allowing the developer to interact with Web services by using traditional ColdFusion-style tags. Also, Dreamweaver MX can introspect these services, and it will automatically create the ColdFusion MX code necessary to utilize the services. See more about Web Services in Joel's article for ASP.NET.

To use a Web Service from within Dreamweaver MX, follow these steps:

1. To locate a public Web service, you can use one of the lists that are available from within the Dreamweaver MX environment, or type in your own WSDL file location:


Dreamweaver MX can use the link to the WSDL page to create the interface for the Web service. The Web service appears with its methods and variables broken down into the Components panel, much like your data sources appear in the Bindings panel. For this example, we've used an Ebay price watcher Web service listed on xMethods. This Web Service has one method and one return parameter:

2. After you've added the Web service to your Components panel, you can drag and drop it onto the page, and Dreamweaver MX will create the code for you, which in this case is a CFINVOKE tag:

<cfinvoke
  webservice="http://www.xmethods.net/sd/2001/EBayWatcherService.wsdl"
  method="getCurrentPrice"
  returnvariable="aCurrentPrice">
  <cfinvokeargument name="auctionId" value="enter_value_here"/>
</cfinvoke>

The method is called getCurrentPrice, and the return variable is aCurrentPrice.

3. Pass it an eBay auction ID number (using the value attribute), and it will return a price in the aCurrentPrice variable. You can do this by hard coding it or by allowing a user to enter a value in a form field, among other methods. For this example, any valid eBay auction item can be added to the value field.

4. Display the result with:

<cfoutput>#aCurrentPrice#</cfoutput>

After doing this, you can browse the page and the result will be displayed.

ColdFusion makes it very easy to consume Web Services. Even without the drag-n-drop functionality of Dreamweaver MX, the <cfinvoke> tag is easy to understand and easy to use. ColdFusion MX also makes it easy to create Web Services. That will be the topic of a future tutorial.

Tom Muck

www.dwteam.com

 

 

Copyright © 2002, DWTeam.com. All Rights Reserved.