0

the following Problem drives me crazy:

I am connected to a SOAP WS with WSDL and p12 certificate. I can call something and get the exception if the method is not correct, or if a Parameter is missing:

"Function ("Test1") is not a valid method for this service"
"SOAP-ERROR: Encoding: object has no 'message' property"

But if everything (I think) is correct, the script stops

try{
$client = new SoapClient(
        $soapUrl,
        array(
                'ssl' => array(
                        'cert' => $cert_file,
                        'certpasswd' => $cert_password),
                        'trace' => 1,
                        'exceptions' => 0
                        )
                )
);

$uuid = gen_uuid();

$SendValue = array('transaction' => Array('uuid'=>$uuid),
                   'message' => '-test message-',
                   'delay' => 0,
                   throwException => 1,
                   forceRollback => 0);
echo "<br>";                 

//           var_dump($SendValue);
        echo "Test Start - ";    // this is printed 
        $result = $client -> Test($SendValue);
            echo " - Test Ende";  // this is not printed anymore and all the below
                echo "<br>OK - Request:\n" . $client->__getLastRequest(). "!\n";


        echo "<pre>";
        print_r($result);
        echo "</pre>";
//-----------------------------------------------------------

echo "<h1>EOF</h1>";
}catch(\Exception $exception)
{
    echo "Did not work...";

 var_dump($exception);
 echo "Request:\n" . $client->__getLastRequest() . "\n";
 echo "Response:\n" . $client->__getLastResponse() . "\n";
}

echo "this is not printed";

Any suggestions please? Thanks a lot in Advance.

  • You'll find that unfortunately some Soap errors are not catchable in PHP. It is what it is... I think I remember reading somewhere that you could create a custom error handler which might be able to handle it, but I think I remember that if the endpoint is down, the SoapClient will throw a fatal error (uncatchable). May not be useful, but thought I'd mention it anyway. – scrowler Dec 04 '18 at 10:30

1 Answers1

0

Looks like you placed the trace option in the wrong place in the configuration array. Rather than

    array(
            'ssl' => array(
                    'cert' => $cert_file,
                    'certpasswd' => $cert_password,
                    'trace' => 1,
                    'exceptions' => 0
                    )
            )

it should be

    array(
            'ssl' => array(
                    'cert' => $cert_file,
                    'certpasswd' => $cert_password,
                    ) 
            'trace' => 1,
            'exceptions' => 0
            )

An effectively unset trace option (when it's in the wrong place, the fallback default 0 is used) causes __getLastRequest() to be unavailable`, so you're probably getting "call to an undefined method error".

The most possible reason you're not seeing this is your runtime php configuration that prevents you from seeing error messages. Refer to PHP's white screen of death to see how you can see the errors.

It can also be that SoapClient throws a different type of exception instead of \SoapFault. Change that type to \Exception and see if you get anything.

Bartosz Zasada
  • 3,762
  • 2
  • 19
  • 25
  • Hello, thanks for your answers. OK, I corrected the trace issue, but it did not help. In Firefox, the page is cut off after the call, and ie gives a http 500 error :/ – user10743349 Dec 05 '18 at 11:55
  • You should still make sure that your error reporting configuration allows you to see all errors (assuming all this happens in the development environment). It's unlikely that PHP or SOAP client returns no error message whatsoever. – Bartosz Zasada Dec 05 '18 at 12:57
  • testTest Start - E_WARNING Error in file »example1.php« at line 90: SoapClient::__doRequest(): SSL operation failed with code 1. OpenSSL Error messages: error:14094418:SSL routines:ssl3_read_bytes:tlsv1 alert unknown ca E_WARNING Error in file »example1.php« at line 90: SoapClient::__doRequest(): Failed to enable crypto E_WARNING Error in file »example1.php« at line 90: SoapClient::__doRequest(): connect() failed: Unspecified error Could not connect to host – user10743349 Dec 17 '18 at 14:37