Web Services with ColdFusion
Since the ‘.NET’ revolution that started half a decade ago, we have been seeing reinventions of our old web programming languages. ASP has become ASP.net, and JSP has too evolved to JSP.net. “Would there be a ColdFusion.net?”, I have wondered. Thankfully ColdFusion has not gone the way of the dinosaurs. Web services are surprisingly easy to implement on ColdFusion, and consuming web services is equally simple.
Before we step into web services, you will need to realize that they are built upon CFCOMPONENT. These tags bundles sets of functions into neat OO-objects which you can in turn instantiate and call on your web pages. Stretching this feature slightly, Adobe now expands this concept to allow the same bundle you have built to serve you information irregardless of your platform or server. Hence the birth of “ColdFusion.Net”.
How do we implement this? Assuming you have been a serious devotee to the OO (Object-Oriented) way and have been practicing CFCOMPONENTs in all your work, it would be as simple as changing one parameter:
daoHelloWorld.cfc
<cfcomponent>
<cffunction name=”sayHelloTo” access=”remote” output=”no” returntype=”string”>
<cfargument name=”name” type=”string” required=”yes”>
<cfset myString = “Hello #name#!”>
<cfreturn myString>
</cffunction>
</cfcomponent>
Save the above codes into your root folder and you have your very first web service on ColdFusion. You may also notice the additional parameter output=”no”. This parameter should be set to “No” since you are not expecting the function print or display anything. All results will be returned to the caller. To inspect your new webservice, you can access via the component browser for this file at http://<your-own-domain>/daoHelloWorld.cfc . Do note that you may need to log into your ColdFusion administrator account to view it.
Now let’s go through how we could consume this new web service. Since this is a ColdFusion blog, let’s see how we could consume web services the ColdFusion way.
<cfinvoke webservice=”http://<your-own-domain>/daoHelloWorld.cfc?wsdl” method=”sayHelloTo” returnvariable=”strg”>
<cfinvokeargument name=”name” value=”James”/>
</cfinvoke><cfoutput>
#strg#
</cfoutput>
Neat isn’t it? Do pay attention to your functions which returns non-string variables. By default complex objects returned via the function will be in WDDX. WDDX are structured XML that was built originally for ColdFusion. When returning WDDX, the other non-ColdFusion server may not have the luxuary of a built-in fuction to convert the XML back into objects. These applications will need to built their own xml parser.

May 23rd, 2009 at 6:54 am
Yet the environment into which these services are deployed is more complex … Web Service