Creating a Web Service with ColdFusion: the Basics
A web service is a software related technology that facilitates machine-to-machine interaction over a network. Web services are used by clients who access the service, and could be written in any programming language. This article will show you how to create a web service using ColdFusion.
Creating a Web Service with ColdFusion: the Basics (Page 1 of 4 )
Before you start creating a web service of any form you should know some basic facts about SOAP, WSDL, XML, and UDDI. Since the web service you may create will reside on a web server before it is made public, you also need to know a few things about web servers. Web services are consumed (used) by clients who access the service. The client software ideally could be written in any programming language, .NET, Java, ColdFusion, Perl, and so on.
Installing ColdFusion on Windows Platform
This tutorial is based on programs developed on a Windows XP Professional machine which has IIS 5.1 installed on it. Since this tutorial deals with creating a web service with ColdFusion, it is assumed that Cold Fusion MX Server software is installed. If you need to know how to install Cold Fusion MX, please read my article on installing CF MX 6.1, which appeared on DevArticles.com. The more recent version, CF MX 7.0 should also be installed along the same lines.
What is a web service?
A web service is a software related technology that facilitates machine-to-machine interaction over a network. The WSDL (Web Services Discovery Language) format is supposed to be understood and processed by all the machines. The WSDL therefore sets up the rules of engagement for this interaction. These rules are enforced by sending the messages to be carried by SOAP (Simple Objects Access Protocol) envelopes. The envelopes are carried and delivered by such all too well known protocols as HTTP, SMTP and others. The language used between machines for interaction will be the now familiar, text format based, XML (eXtensible Markup Language).
A web service, because of its open source origin, should be transparent to the diverse, existing programs and operating systems in its ideal embodiment. The web service when it is ready may be published in what is called a UDDI (Universal Description Discovery Integration) registry, a repository akin to the telephone directory of companies. UDDI is again an open source standard agreed to universally. The best place to learn more about these various acronyms is W3C. You may get a bird's eye view with my other tutorial on ASPFree.com.
Virtual Directories on the IIS
Virtual directories are those directories that are accessed by Internet/intranet users, normally seen in the URL address of the page being browsed. However, the actual files are located somewhere on the machine, more often in the root directory of the host. This way those who arrive at the web page will not actually know where the related file is kept. The web service related files are placed in a Virtual Directory called CF_WebSvc, and the Web client related files consuming this service are placed in another virtual directory called TestingCF as shown in Fig.1. The actual files are kept on the machine at the indicated physical locations.
CF_webSvc----------- C:\Documents and Settings\computer user\
TestingCF----------- C:\Documents and Settings\computer user\
ColdFusion background for Web Service
If you have been developing custom functions and ColdFusion components you are already well on your way to creating a web service. This tutorial assumes that you are starting at the very beginning.
ColdFusion components are almost OOP based but not totally; they have methods and constructs, and they provide reusable code. We will look at it in more detail during this tutorial. However, if you know what functions achieve in any programming language, you are not far from understanding components. They turn functions into objects whose methods can be accessed. ColdFusion function methods morph themselves into ColdFusion Web Service methods via CFC.
If you have read my previous article, you would know that ColdFusion code can be written in two ways: tag based and script based with ColdFusion specific <cfscript/>. You need to know a number of function-specific tags and CFC related tags, such as the following: