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 - Consuming the Service (Page 4 of 4 )
We want to know whether this service is working. How are we going to test it? Easy, let us create a client who will consume this service. Writing client code is not different from writing a CFM page. Of course you use the special tags, like "cfinvoke" which calls up the service. Where does it call it from? This is where the WSDL we spoke of earlier comes in. The functions of the CFC function are similar to the ASMX in the dotNet environment. When you invoke the service, you invoke it with an argument, in this case "Mr.Bond". The return variable is a string which you display as you normally would, with the 'cfoutput' tags. Now you save this as ConsumejustFunction.cfm and store in the appropriate virtual directory.
It's show time! Browse to the 'ConsumejustFunction.cfm', and you will see the following.
It is pretty easy to create a web service in ColdFusion. For those who already know how to write functions and components, it is a snap. When you make changes to the CFC make sure you browse to it and review it in the Control Viewer, otherwise the MX may return a "not found" message.
Coding a consumer is just as easy. All you need to do is provide a WSDL reference, a return variable, and the necessary arguments needed by the service. Although the function used is quite simple, more complex data types as well as data from the backend can be provided with the service. The keyword is interoperability. The consuming client could very well use another programming language, perhaps from a UNIX work station in Outer Mongolia.
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.