spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / coldfusion / 2 current pageTo page 2To page 3To page 4
[next]

Subject Matter Expert - Managed Services (PA)
Next Step Systems
US-PA-Wayne

Justtechjobs.com Post A Job | Post A Resume
Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs


Programming ColdFusion MX: Web Services

This is the conclusion of an excerpt from the book: Programming ColdFusion MX, 2nd Edition by O'Reilly.

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 web services from CFCs that you need to know about:

Example 24-6 calls the web service you just created, using the cfinvoke tag just as you have throughout the chapter.

Example 24-6: Calling a web service produced in ColdFusion MX

<cfinvoke 
  webservice="http://localhost/programmingcf/ch24/helloworld.cfc?wsdl"
  method="getMessage"
  returnvariable="aString">
    <cfinvokeargument name="name" value="Rob"/>
</cfinvoke>
   
<cfoutput>
#aString#
</cfoutput>

Running this example results in the output shown in Figure 24-8.

Figure 24-8. Invoking a web service produced in ColdFusion MX

 

home / programming / coldfusion / 2 current pageTo page 2To page 3To page 4
[next]

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint

Created: March 27, 2003
Revised: Sept 1, 2003

URL: http://webreference.com/programming/coldfusion/2