I looked at the SoapFault object passed to the Frontend. Using getMessage() returns the original message. Using getCode returns 0, but the object has a property called faultcode and faultmessage that contain the original code & message of the exception.
ZendSoapServer looses Error Code when throwing an Exception / SoapFault
-
03-04-2022 - |
题
I have a Zend Backend & a Zend Frontend, both communicating over SOAP. An Exception on the backend, should throw an Exception / SoapFault on the Frontend. This works with the Error-Message, but the Error-Code gets lost somehow. I need the code to be able to show errors in different languages on the frontend. I tried a lot, but couldnt get it to work.
This is the Backend handleSoap function of my SoapController:
private function handleSOAP($class) {
$options = array('uri' => 'urn:'.$class.'','location' => $this->_WSDL_URI);
$server = new Zend_Soap_Server(null, $options);
$server->setEncoding('ISO-8859-1');
$server->setClass($class);
$server->registerFaultException('Exception');
$server->handle();
}
On the Frontend the SoapCallerClass:
public function __construct() {
$this->client = new Zend_Soap_Client($this->_WSDL_URI);
$this->client->setWsdlCache(WSDL_CACHE_NONE);
$this->client->setEncoding('ISO-8859-1');
}
public function __call($method,$params) {
try {
$this->client->mySoapFunction();
} catch (Exception $e) {
throw $e; // No error code inside !
}
}
解决方案
不隶属于 StackOverflow