ColdFusion MX (CFMX) is Macromedia’s reinvention of its award-winning ColdFusion application server. Rebuilt from the ground up and running on top of several popular J2EE servers, CFMX will bring the ease and speed of ColdFusion development to the Java platform. It has some powerful new features such as native XML and XSL functions, direct integration with Flash MX, support for Java objects and JSP tag libraries, and much more. One of its most exciting new features is the ability to easily use Web services.

Flash conference

Did you attend the recent Flash development conference? Click here for more details.

Introducing ColdFusion Components
The first step in creating a Web service with CFMX is to create a ColdFusion Component (CFC). CFCs are a new way to encapsulate and reuse code. CFCs are similar to ColdFusion Custom Tags, but they offer some interesting new options. They also have some object-oriented (OO) properties like methods and inheritance. For this example, I’ll create an extremely simple CFC that takes a day, month, and year and returns the day of the week for that date.

The code is quite simple (see Listing A).

Listing A is self-explanatory, but you might notice several new CFML tags. These are new tags specifically for using CFCs. If I wanted to invoke this CFC, the code to call it is also very simple, as shown in Listing B.

If we ran Listing B in a Web browser, the output would be:
The date May 15, 2002 is on a Wednesday.

CFC = Web service
What does this have to do with Web services? Well, the CFC I created in Listing B can be called in many ways. It can be invoked. It can be called by a form, by a URL, or by Flash MX. And it can be called as a Web service. If we call the CFC using a URL like this: http://localhost/webservice/getdayofweekfromdate.cfc?wsdl

we get the response shown in Listing C in the Web services format.

CFMX automatically handles the creation of the Web service from the CFC. Any other system supporting Web services, like .NET or Java servers, can invoke the CFC I created, regardless of platform or location. Pretty amazing.

Sneak MX Preview

Click here to get your own copy of ColdFusion MX Preview Release.

CFCs offer features like component security, argument type definitions, and component inheritance; they’re even self-documenting. In a future article, I’ll show you how easy it is to consume public Web services from other systems and use them in your CFMX applications.