Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems sending SOAP auth Headers in php

I am very new to SOAP (i.e. no clue!)

I have been asked by a client to interact with an existing SOAP service that requires authentication done through my SOAP headers ( a simple username and password )

I have 3 methods at my disposal,

IsAlive IsAliveSecure ChangeUserDetails

IsAlive simply returns true and I can call it no problem

IsAliveSecure returns true with proper authorisation and I cannot get it to return true.

basically I need to send the following request:

POST /ripplecomprovisioning.asmx HTTP/1.1
Host: provisioning.example.ie
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.blueface.ie/provisioning/IsAliveSecure"

<?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>
    <SoapAuthHeader xmlns="http://www.example.ie/provisioning/">
      <Username>myusername</Username>
      <Password>mypassword</Password>
    </SoapAuthHeader>
  </soap:Header>
  <soap:Body>
    <IsAliveSecure xmlns="http://www.example.ie/provisioning/" />
  </soap:Body>
</soap:Envelope>

My question is how do I send a request formatted like the above in php?

this is what I tried but with no success:

$soapClient = new SoapClient("https://provisioning.example.ie/ripplecomprovisioning.asmx?WSDL");

// Prepare SoapHeader parameters 
$sh_param = array( 
            'Username'    =>    'myusername', 
            'Password'    =>    'mypassword'); 
$headers = new SoapHeader('ripplecomprovisioning', 'SoapAuthHeaders', $sh_param); 

// Prepare Soap Client 
$soapClient->__setSoapHeaders(array($headers)); 
     $result = $soapClient->isAlive();

echo var_dump($result);

echo "<br /><br />";

   $result = $soapClient->IsAliveSecure();

echo var_dump($result);

the output from the above is as follows:

object(stdClass)#3 (1) {
  ["IsAliveResult"]=>
  bool(true)
}
<br /><br />
Fatal error: Uncaught SoapFault exception: [soap:Server] System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.UnauthorizedAccessException: Attempted to perform an unauthorized operation.
   at example.VoIP.Provisioning.RipplecomProvisioningServices.IsAliveSecure()
   --- End of inner exception stack trace --- in /var/www/ripplecomweb/authentication/soap.php:20
Stack trace:
#0 [internal function]: SoapClient->__call('IsAliveSecure', Array)
#1 /var/www/ripplecomweb/authentication/soap.php(20): SoapClient->IsAliveSecure()
#2 {main}
  thrown in /var/www/ripplecomweb/authentication/soap.php on line 20

Any help with this would be greatly appreciated. I cannot afford to fail!!

Thanks

Kev

like image 279
Kevin Bradshaw Avatar asked Nov 14 '22 05:11

Kevin Bradshaw


1 Answers

Well it would be a lot easier if we could see the WSDL of the service. But try these steps:

1.Check the WSDL for the isAliveSecure method to see if you have to pass something to it.

2.See what the request you're sending really looks like:

var_dump($soapClient->__getLastRequest());
var_dump($soapClient->__getLastRequestHeaders());

(make sure you're instantiating $soapClient with the option 'trace' => TRUE for these methods or they won't work -> see PHP manual).

3.Try sending the request in the form that you're sure should be correct manually via command line, something like:

curl -v -k -d @/path/to/the/file/with/the/request/xml http://service_url
like image 114
Christof Avatar answered Nov 17 '22 04:11

Christof