【问题标题】:Zend Framework: catch custom soap exceptionsZend 框架:捕获自定义的肥皂异常
【发布时间】:2011-01-12 00:05:31
【问题描述】:

在请求一个soap web 服务操作时,如何捕获我的自定义soap 错误ProductoInexistente?我的代码如下,但它不起作用:

$_WSDL_URI = 'http://joaquinlrobles.redirectme.net:8080/Pelopincho/PelopinchoService?WSDL';
$ws = new Zend_Soap_Client($_WSDL_URI, array('soap_version' => SOAP_1_1));
try {
 $resultado = $ws->getStockProducto(array('idProducto' => $idProducto));
 $this->view->resultado = $resultado->result;
}
catch (ProductoInexistente $ex) {
 $this->view->resultado = 'Producto Inexistente';
}

谢谢!

【问题讨论】:

    标签: php web-services zend-framework soap exception-handling


    【解决方案1】:

    是否抛出了ProductoInexistente类型的异常?
    尝试将代码更改为

    $_WSDL_URI = 'http://joaquinlrobles.redirectme.net:8080/Pelopincho/PelopinchoService?WSDL';
    $ws = new Zend_Soap_Client($_WSDL_URI, array('soap_version' => SOAP_1_1));
    try {
     $resultado = $ws->getStockProducto(array('idProducto' => $idProducto));
     $this->view->resultado = $resultado->result;
    }
    catch (Exception $ex) {
     var_dump($ex);
    }
    

    看看异常类的名称是什么。
    除非ProductoInexistente 的异常不能被catch(ProductoInexistente $ex) 捕获

    【讨论】:

    • 好吧,通过转储,我可以看到捕获的异常是 ProductoInexistente 异常: object(SoapFault)#53 (9) { ["message:protected"]=> string(25) "comun .ProductoInexistente" ...
    • 其实不是。异常的对象似乎是 SoapFault。因此,如果您尝试 {...} catch(SoapFault $ex) { ... } 您应该捕获异常。
    • 是的,我应该捕获操作引发的所有自定义异常...在 c# 中您应该捕获 System.Services.SoapFault 并且一切正常...我应该在这里做什么分别处理每个抛出的自定义异常?
    猜你喜欢
    • 2011-12-20
    • 1970-01-01
    • 1970-01-01
    • 2010-12-20
    • 2013-10-05
    • 1970-01-01
    • 1970-01-01
    • 2011-05-14
    • 1970-01-01
    相关资源
    最近更新 更多