0

I'm trying to make a soap header that would look like this:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <a-user xmlns="a">testName</a-user>
    <a-pass xmlns="a">testPassword</a-pass>
  </s:Header>
  <s:Body>
    ...
  </s:Body>
</s:Envelope>

I'm pretty new to soap so I'm pretty sure I just don't understand what I'm supposed to put in for the parameters of the SoapHeader constructor, this is what I'm currently trying and it keeps failing to authenticate:

        $authHeader = new SoapHeader("http://schemas.xmlsoap.org/soap/envelope/", "Envelope", array("Header" => array("a-user" => "testName", "a-pass" => "testPassword")));

Can someone explain how I'm supposed to translate that header from the xml into a php soapheader please?

Edit: Yes, agunn, I'm using a real user name and pass, I get a SoapFault exceptions saying "Vendor not authorized!" when I make my soapCall.

Here's the soap call part included:

$this->client->__setSoapHeaders($authHeader);
$response = $this->client->__soapCall("Foo", $params);
uRockNinja
  • 359
  • 3
  • 6
  • So, @uRockNinja, when you say that the Envelope constructor in your code snippet is what you are 'currently trying', you don't mean that literally, do you? That is, you are, in your real code using a real user name and password, right? If so, can you be more specific about your failure message or codes? Your code snippet looks like a reasonable try, so helpers are probably going to need more info in order to help. – Anne Gunn Dec 07 '16 at 19:50
  • Can you add your all soap call part ? – mim. Dec 07 '16 at 19:50

1 Answers1

0
$authHeader = new SoapHeader("http://schemas.xmlsoap.org/soap/envelope/", "Envelope", array("Header" => array("a-user" => "testName", "a-pass" => "testPassword")));

By the SoapClient spec you should try like this

$this->client->__setSoapHeaders(array($authHeader));
$response = $this->client->__soapCall("Foo", $params);
Coke
  • 36
  • 6
  • I forgot to say that you can print/vardump your request to see how it look like. Use echo $this->client->__getLastRequest(); – Coke Dec 07 '16 at 20:40