By David Fekke
January 17th, 2011
One of the developers I work with recently had a problem trying to make Web Service calls to a SOAP based Web method that requires Request Headers. I ran into the same problem about a year ago using CFMX 6.1. Request and response headers for web services are now built into CFMX 7. It is possible to get CFMX 6.1 to send request headers. Here is how you can do it with CFMX 6.1. The first thing you will have to do is make sure CFMX is patched to at least the 6.1 updater (6,1,0,83762) or the hf53566_61.jar hot fix. This patch will cause problems with trying to use cfdump to output the cfcatch variable, but there is also a patch for that as well.
You will need to use the createObject function to create a web service object instead of using cfinvoke to be able to use the request header.
<cfset doc.Authentication = XmlElemNew(doc, "https://www.somecompany.com/services/ ", "Authentication") />
<cfset doc.Authentication.username = XmlElemNew(doc, "username") />
<cfset doc.Authentication.username.XmlText = "myUsername" />
<cfset doc.Authentication.password = XmlElemNew(doc, "password") />
<cfset doc.Authentication.password.XmlText = "myPassword" />
<cfset headerElement.init(jXMLdoc) />
<cfset WSObj.setHeader(headerElement) />
ColdFusion MX 7 handles this now quite well by using addSOAPRequestHeader() function. There is no longer a need to call the underlying java to make these calls.