SOAP WebService with Authentication Header: need duplicate auth structure
Copy link to clipboard
Copied
Hi,
I'm trying to convert some "manual" soap request to the cfinvoke/createObject method, and i find strange to have to do the thing i did ^^
Here is the previous code:
<cfxml variable="LOCAL.SOAP_Request"><cfoutput><?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<AuthenticationHeader xmlns="https://soap.namebay.com/">
<sLogin>#variables.login#</sLogin>
<sPassword>#variables.password#</sPassword>
</AuthenticationHeader>
</soap:Header>
<soap:Body>
<oGetAutoRenew xmlns="https://soap.namebay.com/">
<P_sDomainName>#ndd.domain()#</P_sDomainName>
</oGetAutoRenew>
</soap:Body>
</soap:Envelope></cfoutput></cfxml>
<cfhttp url="https://soap.namebay.com/Domain.asmx?WSDL" method="post">
<cfhttpparam type="header" name="Host" value="soap.namebay.com">
<cfhttpparam type="header" name="Content-Type" value="text/xml;charset=utf-8">
<cfhttpparam type="header" name="Content-Length" value="#len(trim(LOCAL.SOAP_Request))#">
<cfhttpparam type="header" name="SOAPAction" value="https://soap.namebay.com/oGetAutoRenew">
<cfhttpparam type="xml" name="body" value="#trim(LOCAL.SOAP_Request)#">
</cfhttp>
And here is my new code:
<cfset LOCAL.wsNamebay = createObject ( "webservice", "https://soap.namebay.com/Domain.asmx?WSDL" ) />
<cfset LOCAL.doc = XmlNew() />
<cfset LOCAL.doc.AuthenticationHeader = XmlElemNew ( LOCAL.doc, "https://soap.namebay.com/", "AuthenticationHeader" ) />
<cfset LOCAL.doc.AuthenticationHeader.sLogin = XmlElemNew ( LOCAL.doc, "https://soap.namebay.com/", "sLogin" ) />
<cfset LOCAL.doc.AuthenticationHeader.sPassword = XmlElemNew ( LOCAL.doc, "https://soap.namebay.com/", "sPassword" ) />
<cfset LOCAL.doc.AuthenticationHeader.sLogin.XmlText = variables.login />
<cfset LOCAL.doc.AuthenticationHeader.sPassword.XmlText = variables.password />
<cfset addSOAPRequestHeader ( LOCAL.wsNamebay, "ignoredNameSpace", "ignoredName", LOCAL.doc ) />
<!--- FIXME: duplicate, needed don't know why --->
<cfset LOCAL.wsAuth=StructNew() />
<cfset LOCAL.wsAuth["sLogin"]="" />
<cfset LOCAL.wsAuth["sPassword"]="" />
<cfset LOCAL.AutoRenew = wsNamebay.oSetAutoRenew ( LOCAL.ndd.domain(), ARGUMENTS.activate, LOCAL.wsAuth ) />
<cfif LOCAL.AutoRenew.getIReturnCode() eq "200">
<cfreturn true />
<cfelse>
<cfset variables.msg_error = LOCAL.AutoRenew.getSMessage()>
<cfreturn false />
</cfif>
If i remove the LOCAL.wsAuth struct + argument i got the "Web service operation oSetAutoRenew with parameters {domain.com,true} cannot be found." .
If I use an empty struct i got a CF exception with: "Error obtaining parser from data source:AuthenticationHeader cannot be null!"
if i remove the addSOAPRequestHeader line, then i got an webservice error response with "Authentication header cannot be null"
Strangely enough a getSOAPRequest() doesn't show the second arguments structure in any cases ...
Any way to get rid of the LOCAL.wsAuth arg ?
Copy link to clipboard
Copied
Where is the code?
Copy link to clipboard
Copied
Here is the previous code:
<cfxml variable="LOCAL.SOAP_Request"><cfoutput><?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<AuthenticationHeader xmlns="https://soap.namebay.com/">
<sLogin>#variables.login#</sLogin>
<sPassword>#variables.password#</sPassword>
</AuthenticationHeader>
</soap:Header>
<soap:Body>
<oSetAutoRenew xmlns="https://soap.namebay.com/">
<P_sDomainName>#ndd.domain()#</P_sDomainName>
<P_hasAutoRenew>#arguments.activate#</P_hasAutoRenew>
</oSetAutoRenew>
</soap:Body>
</soap:Envelope></cfoutput></cfxml>
<cfhttp url="https://soap.namebay.com/Domain.asmx?WSDL" method="post">
<cfhttpparam type="header" name="Host" value="soap.namebay.com">
<cfhttpparam type="header" name="Content-Length" value="#len(trim(LOCAL.SOAP_Request))#">
<cfhttpparam type="header" name="SOAPAction" value="https://soap.namebay.com/oSetAutoRenew">
<cfhttpparam type="xml" name="body" value="#trim(LOCAL.SOAP_Request)#">
</cfhttp>
And here is the new one:
<cfset var LOCAL={} />
<cfset LOCAL.ndd = createObject("component","components.ndd").init(arguments.domaine)>
<cfset LOCAL.wsNamebay = createObject ( "webservice", "https://soap.namebay.com/Domain.asmx?WSDL" ) />
<cfset LOCAL.doc = XmlNew() />
<cfset LOCAL.doc.AuthenticationHeader = XmlElemNew ( LOCAL.doc, "https://soap.namebay.com/", "AuthenticationHeader" ) />
<cfset LOCAL.doc.AuthenticationHeader.sLogin = XmlElemNew ( LOCAL.doc, "https://soap.namebay.com/", "sLogin" ) />
<cfset LOCAL.doc.AuthenticationHeader.sPassword = XmlElemNew ( LOCAL.doc, "https://soap.namebay.com/", "sPassword" ) />
<cfset LOCAL.doc.AuthenticationHeader.sLogin.XmlText = variables.login />
<cfset LOCAL.doc.AuthenticationHeader.sPassword.XmlText = variables.password />
<cfset addSOAPRequestHeader ( LOCAL.wsNamebay, "ignoredNameSpace", "ignoredName", LOCAL.doc ) />
<!--- FIXME: duplicate, needed don't know why --->
<cfset LOCAL.wsAuth=StructNew() />
<cfset LOCAL.wsAuth["sLogin"]="" />
<cfset LOCAL.wsAuth["sPassword"]="" />
<cfset LOCAL.AutoRenew = wsNamebay.oGetAutoRenew ( LOCAL.ndd.domain(), LOCAL.wsAuth ) />
<cfif LOCAL.AutoRenew.getOGetAutoRenewResult().getIReturnCode() eq "200">
<cfreturn LOCAL.AutoRenew.getP_hasAutoRenew()>
<cfelse>
<cfset variables.msg_error = LOCAL.AutoRenew.getOGetAutoRenewResult().getSMessage()>
<cfreturn "-1">
</cfif>
Copy link to clipboard
Copied
silmaril wrote
<cfset addSOAPRequestHeader ( LOCAL.wsNamebay, "ignoredNameSpace", "ignoredName", LOCAL.doc ) />
AddSOAPRequestHeader should have 5 arguments, in this order:
webservice object
String representing URL of namespace of header
String representing name of header, for example, "AuthenticationHeader"
XML (string) representing value of header
Boolean (True or False) representing the SOAP mustunderstand value for the header
<cfset LOCAL.wsAuth["sLogin"]="" />
<cfset LOCAL.wsAuth["sPassword"]="" />
Shouldn't that be as follows?
<cfset LOCAL.wsAuth["sLogin"]=variables.login />
<cfset LOCAL.wsAuth["sPassword"]=variables.password />
<cfset LOCAL.AutoRenew = wsNamebay.oGetAutoRenew ( LOCAL.ndd.domain(), LOCAL.wsAuth ) />
Shouldn't that be as follows?
<cfset LOCAL.AutoRenew = LOCAL.wsNamebay.oSetAutoRenew ( LOCAL.ndd.domain(), LOCAL.wsAuth ) />
Copy link to clipboard
Copied
BKBK wrote
silmaril wrote
<cfset addSOAPRequestHeader ( LOCAL.wsNamebay, "ignoredNameSpace", "ignoredName", LOCAL.doc ) />
AddSOAPRequestHeader should have 5 arguments, in this order:
webservice object
String representing URL of namespace of header
String representing name of header, for example, "AuthenticationHeader"
XML (string) representing value of header
Boolean (True or False) representing the SOAP mustunderstand value for the header
This was straight from the addSOAPRequestHeader() documentation page.
If you pass XML in the value parameter, ColdFusion ignores the namespace and name parameters. If you require a namespace, define it within the XML itself.
As for the last argument, it is optionnal, and actually i don't understand it's meaning so i left it over, as in the exemple.
<cfset LOCAL.wsAuth["sLogin"]="" />
<cfset LOCAL.wsAuth["sPassword"]="" />
Shouldn't that be as follows?
<cfset LOCAL.wsAuth["sLogin"]=variables.login />
<cfset LOCAL.wsAuth["sPassword"]=variables.password />
That is not necessary, the structure is only here for "function matching",it is not actually used to generate the SOAP call. In fact it shouldn't be necessary ...
<cfset LOCAL.AutoRenew = wsNamebay.oGetAutoRenew ( LOCAL.ndd.domain(), LOCAL.wsAuth ) />
Shouldn't that be as follows?
<cfset LOCAL.AutoRenew = LOCAL.wsNamebay.oSetAutoRenew ( LOCAL.ndd.domain(), LOCAL.wsAuth ) />
Well, as for the "LOCAL." prefix it's simply a quote error,
as for the function name, well both function are used, i didn't quote the same function in both example sorry. In this case oSetAutoRenew need to be called with a third argument like this:
<cfset LOCAL.res = LOCAL.wsNamebay.oSetAutoRenew ( LOCAL.ndd.domain(), true, LOCAL.wsAuth ) />
Copy link to clipboard
Copied
If you don't highlight your code and use the >> Syntax Highlighting options, sometimes your code will become invisible.
The >> should appear at the top when you create a thread. When responding to another post, you have to click "Use Advanced Editor" to get this option.
HTH,
^_^
Copy link to clipboard
Copied
WTF, i did highlight my code and now everything seems gone ....

