Wednesday, April 13, 2011

Consuming Webservice using ColdFusion and SOAP

This is something that has been killing me for sometime, a while back I got a webserive which was required to be called by ColdFusion. All the methods in the webservice used COMPLEX type and it was a pain to use CFINVOKE to consume it, just too much of JAVACAST and other checks, still did not work.

Then I got a post which said to use CFHTTP with SOAP. But the issue was how to generate the SOAP headers ??

Found link, here you can just give the WSDL url and the method name, it will generate the required SOAP header that needs to be send to consume it.. sweet.. that is what I wanted.

Then you can do

<cfsavecontent variable="soap"> 
<cfhttp url="http://YourWebServiceURL(do not include ?wsdl)" method="post">
  <cfhttpparam type="header" name="content-type" value="text/xml"> 
    <cfhttpparam type="header" name="SOAPAction" value=""> 
    <cfhttpparam type="header" name="content-length" value="#len(soap)#"> 
    <cfhttpparam type="header" name="charset" value="utf-8"> 
    <cfhttpparam type="xml" name="message" value="#trim(soap)#">