PHP soap客户端调用停止脚本

时间:2018-12-04 10:11:20

标签: php soap wsdl certificate signed

以下问题使我发疯:

我已通过WSDL和p12证书连接到SOAP WS。如果方法不正确或缺少参数,我可以调用某些东西并获取异常:

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

但是,如果一切(我认为)都正确,则脚本会停止

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";

有什么建议吗?非常感谢。

1 个答案:

答案 0 :(得分:0)

好像您将trace选项放置在配置数组中的错误位置。而不是

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

应该是

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

一个有效未设置的trace选项(当放置在错误的位置时,使用后备默认值0)将导致__getLastRequest()不可用`,因此您可能会收到“呼叫出现未定义的方法错误”。

您没有看到这的最可能原因是您的运行时php配置,它阻止您看到错误消息。请参阅PHP's white screen of death,以了解如何查看错误。

也可能是SoapClient引发了不同类型的异常,而不是\SoapFault。将该类型更改为\Exception,看看是否有任何东西。