I have to call a soap WebService that needs Basic Authentication. I tryed SoapUI with Basic Authentication and its working. WSDL page can be load from Browser correctly. There is no SSL releated problem.
I'm trying to do same call with SoapClient but not working. As I understand (with help of Burp Software) Authentication header isn't send with soapClient.
While I have this problem, I checked nearly all releated questions on StackOverflow and tryed everything that they suggest.
Here is my PHP code I'm working on it:
echo "<pre>";
$WSDL_URL='https://myserver.com/services/?wsdl';
$username='xxx';
$password='yyy';
$params = array(
'login' => $username,
'password' => $password,
'trace' => 0,
'exceptions' => 0,
'location' => $WSDL_URL,
'uri' => $WSDL_URL
);
$soap = new SoapClient(null, $params);
$RESULT = $soap->serviceTest( 'HELLO' );
echo "<h1>ServiceTEST Result:</h1>";
print_r($RESULT);
Here is my error:
SoapFault Object
(
[message:protected] => Client Error
[string:Exception:private] =>
[code:protected] => 0
[file:protected] => /Applications/MAMP/htdocs/soap/test.php
[line:protected] => 24
[trace:Exception:private] => Array
(
[0] => Array
(
[file] => /Applications/MAMP/htdocs/soap/test.php
[line] => 24
[function] => __call
[class] => SoapClient
[type] => ->
[args] => Array
(
[0] => serviceTest
[1] => Array
(
[0] => HELLO
)
)
)
)
[previous:Exception:private] =>
[faultstring] => Client Error
[faultcode] => s:Client
)
I managed to get the list of the services without including login/password in the wsdl request, so yes soapclient is working with this server.
I got a 500 error when using the login and password so it seems to be an issue on server side.
Here is the code that can help you to have more details on soap response
<?php
$username='xxx';
$password='yyy';
$WSDL_URL='https://myserver.com/services/?wsdl';
$params = array(
// witout params it works at least for the wsdl
//'login' => $username,
//'password' => $password
);
try {
$soap = new SoapClient( $WSDL_URL, $params);
$RESULT = $soap->__getFunctions();
print_r($RESULT);
// uncomment that and you'll have the error
//$soap->serviceTest('bob');
}
catch (SoapFault $fault) {
echo "SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})";
}
catch (Exception $e) {
echo $e->getMessage();
echo $e->getTraceAsString();
}