2

I'm trying to access a SOAP API which requires a custom header for authentication. I can create the header fine, as it's just username, password, id, nice and simple, but for some reason when the actual request goes through it only sends username and password, not id.

I create a SoapHeader:

$auth = array("UserName" => $user, "Password" => $password, "ClientId" => $clientId);
$header = new SoapHeader("namespace", "ClientHeader", $auth, FALSE);
$this->client->__setSoapHeaders($header);

I var_dump the created header, client, etc, and verify that UserName, Password and ClientId are all in the header.

SoapClient::__set_state(array(
  Extra Fields Removed
   '__default_headers' => 
  array (
    0 => 
    SoapHeader::__set_state(array(
       'namespace' => 'namespace',
       'name' => 'ClientHeader',
       'data' => 
      array (
        'UserName' => 'name',
        'Password' => 'password',
        'ClientId' => 'id',
      ),
    )),
  ),
))

But when I make a request only UserName and Password get sent:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="namespace>
  <SOAP-ENV:Header>
  <ns1:ClientHeader>
    <ns1:UserName>name</ns1:UserName>
    <ns1:Password>pass</ns1:Password>
  </ns1:ClientHeader>
  </SOAP-ENV:Header>
  Remainder snipped

Anyone have any ideas?

3
  • I've checked the WSDL and it specifies that ClientHeader has all three fields, so it doesn't seem to be an issue with that: <s:complexType name="ClientHeader"><s:sequence><s:element minOccurs="0" maxOccurs="1" name="ClientID" type="s:string"/><s:element minOccurs="0" maxOccurs="1" name="UserName" type="s:string"/><s:element minOccurs="0" maxOccurs="1" name="Password" type="s:string"/></s:sequence><s:anyAttribute/></s:complexType> Commented Mar 3, 2013 at 7:23
  • Have you checked if $cliendId is not null? Commented Mar 3, 2013 at 9:52
  • Yup. And it's present in the header and SoapClient var_dump as the expected value. Commented Mar 3, 2013 at 9:55

1 Answer 1

1

You are setting ClientId when you should be setting ClientID

Sign up to request clarification or add additional context in comments.

1 Comment

Always the simple things one misses.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.