无法处理 PHP 的 SoapServer->handle() 方法中的错误
我使用 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 错误:
听起来就像我自己的问题一样可怕。不过,我并不完全相信这是我的问题,主要是因为涵盖所有这些的 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:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试评论: https://bugs.php.net/bug.php 吗? id=50547#1298563236(页面上的第三条评论)?
我遇到了完全相同的问题(有时是空响应,有时是正确的 SoapFault)。
xdebug_disable()
救了我。Could you try comment: https://bugs.php.net/bug.php?id=50547#1298563236 (third comment on the page)?
I had the exact same problem (sometimes an empty response, sometimes a correct SoapFault).
xdebug_disable()
saved me.如果发送错误的 XML,Zend Framework 会发送 SoapFault 异常:
使用此代码,只有 Exception 被转换为 SoapFault。
但所有 PHP 错误都不会抛出异常,并且 SoapServer 不会显示错误:
我不知道如何始终返回 SoapFault。对不起。
我正在寻找...;)
If you send a bad XML, Zend Framework send a SoapFault Exception :
With this code, only Exception was transformed to SoapFault.
But all PHP Error don't throw Exception and SoapServer not display error :
I don't know how return SoapFault all time. Sorry.
I am searching ... ;)