【问题标题】:PHP soap client call stops scriptPHP soap客户端调用停止脚本
【发布时间】:2019-05-05 17:38:32
【问题描述】:

以下问题让我发疯:

我使用 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";

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

【问题讨论】:

  • 不幸的是,您会发现一些 Soap 错误在 PHP 中是无法捕获的。就是这样......我想我记得在某处读过你可以创建一个可能能够处理它的自定义错误处理程序,但我想我记得如果端点关闭,SoapClient 将抛出一个致命错误(无法捕捉)。可能没用,但我还是想提一下。

标签: php soap wsdl certificate signed


【解决方案1】:

您似乎将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,看看是否有任何收获。

【讨论】:

  • 您好,感谢您的回答。好的,我更正了跟踪问题,但没有帮助。火狐浏览器调用后页面被截断,ie报http 500错误:/
  • 您仍然应该确保您的错误报告配置允许您查看所有错误(假设所有这些都发生在开发环境中)。 PHP 或 SOAP 客户端不太可能不返回任何错误消息。
  • testTest Start - E_WARNING 文件 »example1.php« 第 90 行出错:SoapClient::__doRequest(): SSL 操作失败,代码为 1。OpenSSL 错误消息:错误:14094418:SSL 例程:ssl3_read_bytes :tlsv1 alert unknown ca E_WARNING 文件 »example1.php« 第 90 行出错:SoapClient::__doRequest():无法启用加密 E_WARNING 文件 »example1.php« 第 90 行出错:SoapClient::__doRequest(): 连接() failed: Unspecified error 无法连接到主机
猜你喜欢
  • 2016-06-20
  • 1970-01-01
  • 1970-01-01
  • 2016-06-03
  • 2014-10-11
  • 1970-01-01
  • 2015-05-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多