Skip to main content
Known Participant
March 3, 2017
Question

SOAP WebService with Authentication Header: need duplicate auth structure

  • March 3, 2017
  • 2 replies
  • 1372 views

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 ?

This topic has been closed for replies.

2 replies

WolfShade
Legend
March 3, 2017

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,

^_^

silmarilAuthor
Known Participant
March 10, 2017

WTF, i did highlight my code and now everything seems gone ....

Inspiring
March 3, 2017

Where is the code?

silmarilAuthor
Known Participant
March 10, 2017

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>

BKBK
Community Expert
Community Expert
March 12, 2017

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  ) />