Producing Web Services

Producing (or publishing, as it’s sometimes referred to) web services in ColdFusion MX is a very simple proposition. In fact, many people have made the claim that it is the easiest way to create and publish web services. While I won’t go that far, I can say that claim is not far from the mark. In essence, you already know everything necessary to publish a simple web service: you learned it back in Chapter 22, ColdFusion Components.

To convert a CFC into a web service, all you need to do is set to remote the access attribute of any component methods (cffunction) you want to expose as web services. That’s all there is to it. To show you just how easy it is to produce a web service in ColdFusion MX, consider the code shown in Example 24-5. After you’ve entered the code, save it under webroot\programmingcf\ch24 as helloworld.cfc.

Example 24-5. Producing a simple web service in ColdFusion MX

<cfcomponent>
  <cffunction name="getMessage" access="remote" returntype="string"
              output="no">
    <cfargument name="name" type="string" required="yes">
    
    <cfreturn "Hello " & arguments.name &"! " & "I've been invoked as a web
      service.">             
  </cffunction>
</cfcomponent>

After looking at this code, your first reaction was probably that it looks just like a regular CFC. That’s because it is a regular CFC. All that really separates a CFC from a web service is setting the access attribute of whatever method(s) you want to expose to remote. There are a few additional rules for creating ...

Get Programming ColdFusion MX, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.