Failed to call XML Soap using PHP SoapClient

Tags: , , ,

I’m trying to call SOAP xml using PHP SoapClient. However, I got the error of

org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class ” for connect URL ‘null’

This is my code for using SoapClient.

$headers = array(
    "POST /AGS/services/GetVIXNCD HTTP/1.1",
    "SOAPAction: """,
    "Accept: text/xml",
    "Cache-Control: no-cache",
    "Pragma: no-cache", 
    "Content-Type: text/xml; charset=utf-8 ",
    "Authorization: Bearer " . $token, //to post from end user
    "Content-Length: " . $this->getXmlLength($request)

$client = new SoapClient('', $headers);

$arrExtraParam = array (
    'paramIndicator' => $paramIndicator,
    'paramRemark' => $paramRemark,
    'paramValue' => $paramValue,

$params = array (
    'agentcode' => $agentcode,
    'arrExtraParam' => $arrExtraParam,
    'bizregno' => $bizregno,
    'compcode' => $compcode,
    'newic' => $newic,
    'oldic' => $oldic,
    'passportno' => $passportno,
    'regno' => $regno,
    'requestid' => $requestid,
    'signature' => $signature
$response = $client->__soapCall('getVixNcdResult', $params);

But I have successfully sent a SOAP request to the server using curl. This is my code.

$url = $soapUrl;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec($ch);

if($result === false) {

    $err = 'Curl error: ' . curl_error($ch);
    print $err;

} else {


    try {

        $xml = simplexml_load_string($result);
        $xml->registerXPathNamespace('success', 'http://servlet');
        $resultAfter = (array) $xml->xpath('//success:getVixNcdReqReturn')[0];

    } catch (Exception $fault) {

        return response()->json($fault->getMessage());

    return response()->json($resultAfter);

Within the try block, I parse the xml into an array. However, this will only happen if the XML response return the intended data. I want to get the message of the fault string of the XML of this.

<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="">
            <faultcode xmlns:axis2ns15="">axis2ns15:Client</faultcode>
            <faultstring>Authentication Failure</faultstring>
            <detail>Invalid Credentials</detail>

Can somebody help me to parse the fault error of the XML or find a way to successfully connect using SoapClient? Thank you.


I have found a way to get the error message of the xml.

$xml = simplexml_load_string($result);
$faultstring = (array) $xml->xpath('//faultstring')[0];
$detail = (array) $xml->xpath('//detail')[0];

return response()->json(['faultstring' => $faultstring[0], 'detail' => $detail[0]]);

This will then return:

{“faultstring”:”Authentication Failure”,”detail”:”Invalid Credentials”}

This may not be the best solution, but for now this works for me.

Source: stackoverflow