views:

285

answers:

1

how do I catch my custom soap fault ProductoInexistente when requesting a soap web service operation? my code is the following, but it's not working:

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

thanks!

A: 

Is there the exception of type ProductoInexistente thrown?
Try changing the code to

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

And see what's the name of exception class.
Unless the exception of ProductoInexistente it cannot be caught by catch(ProductoInexistente $ex)

michal kralik
well, with the dump I can see that that caught exception is a ProductoInexistente exception: object(SoapFault)#53 (9) { ["message:protected"]=> string(25) "comun.ProductoInexistente" ...
Joaquín L. Robles
Well actually it's not. The exception's object seems to be SoapFault. So if you do try {...} catch(SoapFault $ex) { ... } you should catch the exception.
michal kralik
yes, i should catch ALL custom exceptions thrown by the operation... in c# you should catch System.Services.SoapFault<ProductoInexistente> and it's all OK... and what should I do here to process every custom exception thrown separately?
Joaquín L. Robles