If you know how to create a function in ColdFusion, or any programming language for that matter, you have a solid understanding of how to create a web service in ColdFusion. Basically, in ColdFusion you create a web service by writing a function and wrapping it in a special tag. So now you're ready to see how it's done!
The steps for creating a web service in ColdFusion are:
The first web service you will build returns some text to the consumer of the web service. First, you create a document that uses the cfcomponent tag. ColdFusion components have many uses, one of which is acting as a wrapper tag for functions that provide the application functionality you want your web service to provide. So, to build a web service, you must create a document and place opening and closing cfcomponent tags in the document.
Next, you insert function with the cffunction tag, inside the cfcomponent tag. Specify three attributes for your function. They are:
returntype to void.remote for the function to be used as a web service.The simple web service is going to return a string. To return values in a ColdFusion function you use the cfreturn tag.
Now you are going to actually build the web service yourself.
Create a new document and save it as Simple.cfc in C:\CFusionMX\devnet\ws.
Note: There is a reason the file name started with an uppercase letter. CFCs are ColdFusion's implementation of parts of object-oriented programming, and you are creating a class with the CFC. Best practices in OOP say that class names should be uppercase.
cfcomponent tags.cffunction tags within the cfcomponent tags.In the cffunction tag, add the following attributes:
<cfcomponent> <cffunction name="firstws" access="remote" returntype="string"> <cfreturn "Developer Center is great!"> </cffunction> </cfcomponent>