Skip to main content
Inspiring
October 16, 2008
Answered

Can CF do Custom Web Service Headers?

  • October 16, 2008
  • 1 reply
  • 398 views
I am trying to consumer a web service created in .NET that appears to use a custom Header object for authentication. I'm banging my head against the wall trying to figure out how to configure the WS invoke from CF so that it creates the correct SOAP.

Normally I would try and create a CF Structure and pass it into the web service call.
e.g.:

objWS = CreateObject("webservice", " http://www.somesite.com/webservices/myMethod.asmx?WSDL");

myAuthHeader = {username="user1",password="pass1"};

addSOAPRequestHeader(obj, " http://www.somesite.com/webservices/", "AuthenticationHeader", myAuthHeader);


But that gives me the following result:

<soapenv:Header>
<ns1:AuthenticationHeader soapenv:mustUnderstand="true" soapenv:role=" http://schemas.xmlsoap.org/soap/actor/next" xmlns:ns1=" http://www.somesite.com/webservices/">
<item xmlns:ns2=" http://xml.apache.org/xml-soap">
<key xsi:type="xsd:string">USERNAME</key>
<value xsi:type="xsd:string">user1</value>
</item>
<item>
<key xsi:type="xsd:string">PASSWORD</key>
<value xsi:type="xsd:string">pass1</value>
</item>
</ns1:AuthenticationHeader>
</soapenv:Header>

Instead of:

<soap:Header>
<AuthenticationHeader xmlns=" http://www.somesite.com/webservices/">
<UserName>user1</UserName>
<Password>pass1</Password>
</AuthenticationHeader>
</soap:Header>

Anyone have an ideas on what I'm doing wrong?

Thanks!
This topic has been closed for replies.
Correct answer insuractive
Wouldn't you know it - after searching/attempting for hours to try and figure it out, I stumbled over the solution about 10 minutes after posting this. For anyone interested, the answer can be found here:

http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=webservices_24.html

The secret - create your custom element as an XML string, parse it into an object and then pass it to your webservice using the addSOAPRequestHeader function:

<cfsavecontent variable="myXML">
<AuthenticationHeader xmlns=" http://www.somesite.com/webservices/">
<UserName>user1</UserName>
<Password>pass1</Password>
</AuthenticationHeader>
</cfsavecontent>
<cfset xmlObj = xmlParse(myXML)>

...

addSOAPRequestHeader(objWS, " http://www.somesite.com/webservices/", "AuthenticationHeader", xmlObj);

1 reply

insuractiveAuthorCorrect answer
Inspiring
October 16, 2008
Wouldn't you know it - after searching/attempting for hours to try and figure it out, I stumbled over the solution about 10 minutes after posting this. For anyone interested, the answer can be found here:

http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=webservices_24.html

The secret - create your custom element as an XML string, parse it into an object and then pass it to your webservice using the addSOAPRequestHeader function:

<cfsavecontent variable="myXML">
<AuthenticationHeader xmlns=" http://www.somesite.com/webservices/">
<UserName>user1</UserName>
<Password>pass1</Password>
</AuthenticationHeader>
</cfsavecontent>
<cfset xmlObj = xmlParse(myXML)>

...

addSOAPRequestHeader(objWS, " http://www.somesite.com/webservices/", "AuthenticationHeader", xmlObj);