2010-02-02 103 views
0

如何在請求soap web服務操作時捕獲自定義soap故障ProductoInexistente?我的代碼如下,但它不工作:Zend Framework:捕獲自定義肥皂異常

$_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'; 
} 

謝謝!

回答

0

是否有拋出類型爲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)

+0

抓住良好,轉儲我可以看到,該捕獲到的異常是ProductoInexistente例外: 對象(的SOAPFault)#53(9){[「消息:保護「] =>字符串(25)」comun.ProductoInexistente「... – 2010-02-02 14:17:56

+0

實際上它不是。異常的對象似乎是SoapFault。因此,如果您嘗試{...} catch(SoapFault $ ex){...},您應該捕獲異常。 – 2010-02-02 16:03:28

+0

是的,我應該捕獲操作引發的所有自定義異常...在C#中,您應該捕獲System.Services.SoapFault ,它都可以......我應該在這裏處理每個自定義異常單獨拋出? – 2010-02-03 14:28:31