【问题标题】:ZendSoapServer looses Error Code when throwing an Exception / SoapFaultZendSoapServer 在抛出异常/SoapFault 时丢失错误代码
【发布时间】:2013-04-04 14:34:57
【问题描述】:

我有一个 Zend 后端和一个 Zend 前端,它们都通过 SOAP 进行通信。后端出现异常,应在前端抛出异常/SoapFault。这适用于错误消息,但错误代码会以某种方式丢失。我需要代码能够在前端以不同语言显示错误。我尝试了很多,但无法让它工作。

这是我的 SoapController 的 Backend handleSoap 函数:

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();  
}

在前端的 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 !
       }
    }

【问题讨论】:

    标签: php zend-framework exception soap error-code


    【解决方案1】:

    我查看了传递给前端的 SoapFault 对象。使用 getMessage() 返回原始消息。使用 getCode 返回 0,但该对象有一个名为 faultcode 和 faultmessage 的属性,其中包含异常的原始代码和消息。

    【讨论】:

      猜你喜欢
      • 2020-09-27
      • 1970-01-01
      • 1970-01-01
      • 2012-09-14
      • 2021-07-08
      • 2011-10-30
      • 1970-01-01
      • 1970-01-01
      • 2012-11-28
      相关资源
      最近更新 更多