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 - Turn the function into a Web Service (Page 3 of 4 )
In this step you will turn this function into a web service by using the CFC tags. This is the easy part. The web service we create using this function will be called justFunction.cfc. CFCs have this extension, and this is important to note. Here is the code for this CFC.
<cffunction name="WelcomeMsg" access="remote" returntype="string"
<cfargument name="name" type="string" required="yes">
<cfreturn "<h3><font color='blue'>Welcome to my Web Service Site</font>
</h3> " & arguments.name &"! " & "What would you like to do?">
First of all, you notice that the function code is nested in the cfcomponent tags. You also notice that a couple more attributes are added to the function. The web service is accessed remotely and therefore the access is set to 'remote'. Since it is a service you cannot access it directly for an output, so we have set it for 'no' output. Actually, when your consumer calls, this service gets it for you, after massaging what he gets from the server. The tag cfreturn is also needed, because this is what the service returns.
Now you save it in the other directory mentioned earlier, CF_WebSvc. Now, let us see what happens if we access this file with your browser. This is a component, so it should be viewed with a component browser. This is what you will see.
Now if you have permission to log on to this screen (go back to the installation at the very beginning; I could because I am the admin, and in fact the only user), you enter and click on Login. This is what you will see. It's the description of the service and the methods therein. You will see that WelcomeMsg() is a method that takes a string argument. Well, folks, this is all there is to it. When this service is called by the consumer, he or she should provide a string.