本文介绍了PHP SoapFault没有被异常处理程序捕获的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是PHP异常处理和SOAP的新手。由于某种原因,我无法捕捉到SoapFault。我不知道为什么肥皂服务器不是我的。

  try {
$ contact_id = $ objSoapClient-> getContactIdFromVisitorId('12345' );
}
catch(SoapFault $ sf){
echoSoapfault;
}
catch(异常$ e){
echoException;
}

我故意传递不好的身份12345.当我启用错误我看到以下消息 SoapFault异常:[SOAP-ENV:Client]访问者ID无效。但是,我的抓取SoapFault阻止或我的catch异常块被击中。为什么?

解决方案

问题原来是我的SoapClient声明。有一个异常参数必须设置为使异常触发。

  $ objSoapClient = new SoapClient('https: //mywebservice.com/foo.wsdl',array(
trace=> false,
exceptions=> true,//< --------- -----这个!!!
'login'=>'username',// username
'password'=>'password',// password
'features' => SOAP_SINGLE_ELEMENT_ARRAYS + SOAP_USE_XSI_ARRAY_TYPE
));


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

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?

解决方案

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没有被异常处理程序捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 09:37