我是 PHP 异常处理和 SOAP 的新手.出于某种原因,我无法捕获 SoapFault.我不知道为什么.肥皂服务器不是我的.
I am new to PHP exception handling and SOAP. For some reason I cannot catch a SoapFault. I don't know why. The soap server is not mine.
try {
$contact_id = $objSoapClient->getContactIdFromVisitorId('12345');
}
catch (SoapFault $sf) {
echo "Soapfault";
}
catch (Exception $e) {
echo "Exception";
}
我故意传入错误 ID 12345.当我启用错误时,我看到以下消息 SoapFault 异常:[SOAP-ENV:Client] Invalid Visitor ID
.但是,我的 catch SoapFault 块和我的 catch Exception 块都被击中.为什么?
I am purposely passing in the bad id 12345. When I enable errors I see the following message SoapFault exception: [SOAP-ENV:Client] Invalid Visitor ID
. However, my catch SoapFault block nor my catch Exception block ever get hit. Why?
问题出在我的 SoapClient 声明上.必须设置一个异常参数才能触发异常.
The problem turned out to be my SoapClient declaration. There is an exceptions parameter that must be set in order for the exceptions to trigger.
$objSoapClient = new SoapClient('https://mywebservice.com/foo.wsdl', array(
"trace" => false,
"exceptions" => true, // <-------------- This!!!
'login' => 'username', //username
'password' => 'password', //password
'features' => SOAP_SINGLE_ELEMENT_ARRAYS + SOAP_USE_XSI_ARRAY_TYPE
));
这篇关于PHP SoapFault 没有被异常处理程序捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!