6 Replies Latest reply on Mar 13, 2017 1:27 AM by silmaril

    SOAP WebService with Authentication Header: need duplicate auth structure

    silmaril Level 1

      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:

       

       

      And here is my new code:

       

      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 ?

        • 2. Re: SOAP WebService with Authentication Header: need duplicate auth structure
          WolfShade Level 4

          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,

           

          ^_^

          • 3. Re: SOAP WebService with Authentication Header: need duplicate auth structure
            silmaril Level 1

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

            • 4. Re: SOAP WebService with Authentication Header: need duplicate auth structure
              silmaril Level 1

              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>

              • 5. Re: SOAP WebService with Authentication Header: need duplicate auth structure
                BKBK Adobe Community Professional & MVP

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

                • 6. Re: SOAP WebService with Authentication Header: need duplicate auth structure
                  silmaril Level 1

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