无法处理 PHP 的 SoapServer->handle() 方法中的错误

发布于 2024-09-08 13:15:22 字数 893 浏览 11 评论 0原文

我使用 PHP 5.3 创建了一个基于 WSDL 的 SOAP Web 服务。我使用 Zend Framework 来处理该服务,而 ZF 又位于 PHP 的内置 SoapServer 类之上。

在使用 SoapUI 进行测试时,我发现传递无效类型的参数(例如,当 WSDL 定义整数时传递字符串)会导致空响应。深入研究代码,我发现当 ZF 调用 SoapServer->handle() 时,执行会因以下致命错误而终止:

Fatal error: SOAP-ERROR: Encoding: Violation of encoding rules

该错误是有道理的,但对于我来说,我无法弄清楚如何捕获它,以便我可以优雅地处理它。我的理解是,handle()应该抛出异常,但它只是死了。

但这就是真正奇怪的地方......

使用 SoapUI 运行多个测试,而不进行任何代码更改,会产生不同的结果。大多数时候,我得到的是空响应,但偶尔,我会得到一个 SoapFault(这是我所期望的!)。然而,它并不一致,我无法弄清楚是什么触发了它。据我所知,我关闭了 SoapUI 中的缓存功能以及 WSDL 缓存。我不知道是 SoapUI 还是 PHP 的问题。正如我所说,很奇怪。

相关的是,我发现了这个旧的 PHP 错误:

http://bugs.php.net/36629

听起来就像我自己的问题一样可怕。不过,我并不完全相信这是我的问题,主要是因为涵盖所有这些的 PHP 文档以及 ZF 的文档都非常不完整。因此,我很可能只是在做一些非常错误的事情而不自知。有鉴于此,我希望看到一个简单的 shell,它显示了捕获和处理错误的正确方法。但我会接受人们能够提供的任何帮助。

I've created a WSDL-based SOAP web service using PHP 5.3. I'm using Zend Framework to handle the service, and ZF in turn is layered atop PHP's built-in SoapServer class.

In testing with SoapUI, I discovered that passing a parameter of invalid type (e.g., passing a string when an integer is defined by the WSDL) resulted an empty response. Digging into the code, I discovered that when ZF calls SoapServer->handle(), execution dies with this fatal error:

Fatal error: SOAP-ERROR: Encoding: Violation of encoding rules

The error makes sense, but for the life of me, I cannot figure out how to capture it so that I may gracefully handle it. My understanding is that handle() should throw an exception, but it's instead simply dying.

But here's where it gets really weird....

Running multiple tests with SoapUI, without making any code changes, produces different results. Most of the time, I get the empty response, but occasionally, I get back a SoapFault (what I'd expect!). It's not consistent, however, and I cannot figure out what triggers it either way. As far as I can tell, I have the caching features in SoapUI turned off, as well as WSDL caching. I don't know if it's something with SoapUI or PHP. As I said, weird.

Related, I found this old PHP bug:

http://bugs.php.net/36629

that sounds an awful like my own problem. I'm not completely convinced, though, that that's my issue, mostly because the PHP documentation covering all this, as well as the docs for ZF, are woefully incomplete. Thus, I may very well simply be doing something terribly wrong and not know it. In light of that, I'd love to see a simple shell that shows the proper way to trap and handle errors. But I'll take any help that folks out there may be able to offer.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼藏柔 2024-09-15 13:15:22

您可以尝试评论: https://bugs.php.net/bug.php 吗? id=50547#1298563236(页面上的第三条评论)?

Xdebug 可能是问题所在。在调用之前使用 xdebug_disable() 时
handle() 方法时,服务器会用正确的 SOAP 消息进行响应,该消息表示
出了点问题。

我遇到了完全相同的问题(有时是空响应,有时是正确的 SoapFault)。 xdebug_disable() 救了我。

Could you try comment: https://bugs.php.net/bug.php?id=50547#1298563236 (third comment on the page)?

Xdebug might be the problem. When using xdebug_disable() before calling the
handle() method, the server responds with a proper SOAP message which says that
something went wrong.

I had the exact same problem (sometimes an empty response, sometimes a correct SoapFault). xdebug_disable() saved me.

桃扇骨 2024-09-15 13:15:22

如果发送错误的 XML,Zend Framework 会发送 SoapFault 异常:

// Zend/Soap/Server.php line 818
try {
    $this->_setRequest($request);
} catch (Zend_Soap_Server_Exception $e) {
    $setRequestException = $e;
}

使用此代码,只有 Exception 被转换为 SoapFault。
但所有 PHP 错误都不会抛出异常,并且 SoapServer 不会显示错误:

// Zend/Soap/Server.php line 857
protected function _initializeSoapErrorContext()
{
    $displayErrorsOriginalState = ini_get('display_errors');
    // Delete this line to view error in developement
    ini_set('display_errors', false);

    set_error_handler(array($this, 'handlePhpErrors'), E_USER_ERROR);
    return $displayErrorsOriginalState;
}

我不知道如何始终返回 SoapFault。对不起。
我正在寻找...;)

If you send a bad XML, Zend Framework send a SoapFault Exception :

// Zend/Soap/Server.php line 818
try {
    $this->_setRequest($request);
} catch (Zend_Soap_Server_Exception $e) {
    $setRequestException = $e;
}

With this code, only Exception was transformed to SoapFault.
But all PHP Error don't throw Exception and SoapServer not display error :

// Zend/Soap/Server.php line 857
protected function _initializeSoapErrorContext()
{
    $displayErrorsOriginalState = ini_get('display_errors');
    // Delete this line to view error in developement
    ini_set('display_errors', false);

    set_error_handler(array($this, 'handlePhpErrors'), E_USER_ERROR);
    return $displayErrorsOriginalState;
}

I don't know how return SoapFault all time. Sorry.
I am searching ... ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文