Grug
Grug

Reputation: 1890

PHP Soap authentication header

Sample Request:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="https://ws.intermedia.net/Account/Management">

<soapenv:Header>
  <AuthentificationInfo>
     <login>[PLRAdminUserName]</login>
     <password>[PLRAdminPassword]</password>
     <accountID>[accountID]</accountID>
  </AuthentificationInfo>
</soapenv:Header>
<soapenv:Body>
  <GetAccount>
     <accountID>[accountID]</accountID>
  </GetAccount>
</soapenv:Body>
</soapenv:Envelope>

WSDL: https://controlpanel.msoutlookonline.net/WebServices/Account/AccountService.asmx?WSDL

PHP:

    ini_set("soap.wsdl_cache_enabled", "0");

    $wsdl = "https://controlpanel.msoutlookonline.net/WebServices/Account/AccountService.asmx?WSDL";
    $ns = 'https://ws.intermedia.net/Account/Management';

    $client = new SoapClient($wsdl, array(
        "trace" => 1,
        "exceptions" => 0
    ));

    $login = 'xxxx';
    $password = 'xxxx';
    $partnerID = 1234;
    $accountID = 12345678;

    $headerBody = array('AuthentificationInfo'=>array(
        'login' => $login,
        'password' => $password,
        'accountID' => $partnerID
    ));
    $header = new SoapHeader($ns, 'AuthentificationInfo', $headerBody);
    $client->__setSoapHeaders($header);
    $client->__soapCall("echoVoid", array(null));

    $value = $client->GetAccount($accountID);

I'm getting the following error message:

soap:ServerServer was unable to process request. ---> Access denied; Code: 0x0008

Can anyone see anything wrong with the code?

Upvotes: 1

Views: 19280

Answers (3)

bart2puck
bart2puck

Reputation: 2522

just for anyone else that may ever run across this:

I changed

$ns = 'https://ws.intermedia.net/Account/Management';

to:

$ns = 'http://schemas.msoutlookonline.net';

Upvotes: 2

Grug
Grug

Reputation: 1890

I had an incorrect namespace.

Also Mikaël DELSOL's answer helped as I didn't need the array('AuthentificationInfo'=> part. Also didn't need: $client->__soapCall("echoVoid", array(null));

Thank you!

Upvotes: 1

Mika&#235;l DELSOL
Mika&#235;l DELSOL

Reputation: 760

Try with

     $headerBody = array(
      'login' => $login,
      'password' => $password,
      'accountID' => $partnerID);

Upvotes: 5

Related Questions