1

I'm trying to create custom header using PHP SOAP CLient which will looks like

  <soap:Header>
    <AuthorizationToken xmlns="http://www.avectra.com/OnDemand/2005/">
      <Token>string</Token>
    </AuthorizationToken>   </soap:Header>

My code looks like:

      $client = new SoapClient("http://nftpsandbox.avectra.com/xweb/netFORUMXMLONDemand.asmx?WSDL",array("trace" => 1));

    try {

        $header = new SoapHeader('http://www.avectra.com/OnDemand/2005/', 'AuthorizationToken', $token, false);
        $client->__setSoapHeaders(array($header));              

        $result = $client->CheckEWebUser(array('szEmail' => $userName , 'szPassword' => $password));

    }
    catch (SoapFault $result)
    {
        echo $result->faultstring;
    }   

    catch   (Exception $result){
    } 

But Request header which I'm getting looks like:

<SOAP-ENV:Header>
  <ns1:AuthorizationToken>
     <ns1:Token></ns1:Token>
  </ns1:AuthorizationToken>
</SOAP-ENV:Header>

Any idea why node Token is empty when $token has a value?

3
  • Can you do a var_dump on $token before creating soapheader? Commented Nov 14, 2011 at 21:30
  • var_dump result: object(SimpleXMLElement)#4 (1) { [0]=> string(36) "beec45e3-fd5d-418f-a9a6-60566f010eec" } Commented Nov 14, 2011 at 21:32
  • Also when I switch code to $auth = array('ns1:Token'=>$token); $authvar = new SoapVar($auth, SOAP_ENC_OBJECT); $header = new SoapHeader('avectra.com/OnDemand/2005', 'AuthorizationToken', $authvar, false); $client->__setSoapHeaders(array($header)); I'm getting token value but as BOGUS tag. Commented Nov 14, 2011 at 21:35

1 Answer 1

3

SimpleXMLLement can be to hard to handle, try passing simple instance of stdClass

$auth = new stdClass();
$auth->Token = '123';

$header = new SoapHeader('http://www.avectra.com/OnDemand/2005/', 'AuthorizationToken', $auth, false);
Sign up to request clarification or add additional context in comments.

1 Comment

Great. Got it to work. BTW is there any way to retrieve token from the header (stackoverflow.com/questions/8124861/…).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.