Comusming both CFMX and Java Web Services

July 23, 2004 · No Comments

Strangely enough, creating Java web services is just as easy as creating ColdFusion web services. And you can easily consume both. Here's a ridiculously easy and completely useless example of how to do it. First, our .cfc
<cfcomponent displayname="HelloWebService">
   <cffunction access="remote" output="No" name="getHello"
returntype="string">

   
      <cfreturn "Hello, I'm a ColdFusion Web Service" />
   </cffunction>
</cfcomponent>
Nothing there you haven't seen before. Now for our Java Web Service.
public class HelloWebService
{
   public String getHello()
   {
      return "Hello, I'm a Java Web Service";
   };
};
I think it's fairly obvious what's happening in the code above. Now to consume it all you need is something like so...
<ul>
   <li><a href="webservice.cfm?ws=CFML">CFML Hello webservice</a></li>
   <li><a href="webservice.cfm?ws=JAVA">JAVA Hello webservice</a></li>
</ul>

<cfif IsDefined("url.ws")>
   <cfswitch expression="#url.ws#">
   <cfcase value="cfml">
   <cfset objHello = createObject('webservice',
'http://dev.creative-restraint.co.uk/HelloWebService.cfc?WSDL')>

   <cfoutput>
   #objHello.getHello()#
   </cfoutput>
   </cfcase>
   <cfcase value="JAVA">
   <cfset objHello = createObject('webservice',
'http://dev.creative-restraint.co.uk/HelloWebService.jws?WSDL')>

   <cfoutput>
   #objHello.getHello()#
   </cfoutput>
   </cfcase>
   </cfswitch>
</cfif>
And there you go. A completely useless example but at least you know you can do it. Oh, I should point out that this works on CFMX Standard as well as Enterprise.

Tags: ColdFusion · Java

0 response s so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

Leave a Comment

Leave this field empty: