Saturday, 8 November 2014

Coldfusion : Create and consume web service in coldfusion


To Create a webservice in coldfusion all we need to do is create cfc first and write a function having acess as “remote”. That’s it.Coldfusion will automatically create a WSDL file for this webservice which can be viewed through browser (localhost:8500/Coldfusion/webservice/User.cfc?wsdl) or through coldfusion administrator (Data Services à web services)


<!---  User.cfc --->
<cfcomponent output="false">
      <cffunction access="remote" name="display_user" returntype="string">
            <cfargument name="user" type="string">
            <cfreturn "Hello"' ' & user>
      </cffunction>
</cfcomponent>


The above created web service can be consumed in coldfusion as follow –

<!--- display_user.cfm --->
<cfinvoke  webservice="http://localhost:8500/coldfusion/webservice/user.cfc?wsdl"
            method="display_user"
          returnvariable="return_message" >
            <cfinvokeargument  name="user" value="dattatray">
</cfinvoke>
<cfoutput>#return_message#</cfoutput>

No comments:

Post a Comment