ASP .NET SOAP 服务无法针对某些请求反序列化 XML

发布于 2024-12-23 09:15:50 字数 920 浏览 0 评论 0原文

我有一个使用 PHP 的 SoapClient 类调用的 ASP .NET SOAP 服务。一般来说,我调用的服务方法可以工作,但对于某些特定的情况,它始终会失败。当失败时,服务将在大约 90 秒后超时。

我已将问题的根本原因追溯到 ASP .NET 服务,该服务试图反序列化所提供的 XML。在日志中,.NET 服务似乎认为 XML 被截断:

System.Xml.XmlException:发生意外的文件结束。以下元素未关闭:ns1:Description、[...]、SOAP-ENV:Body、SOAP-ENV:Envelope

System.InvalidOperationException: XML 文档中存在错误 (2, 9383)

在我的 PHP 代码中,我我通过调用 $client->__getLastRequest() 来记录请求中使用的 XML。提供的 XML 有效,并且不存在任何可能破坏反序列化的异常字符。

更奇怪的是,失败的不仅仅是一个请求。我可以持续让三个请求失败。

其中两个请求的长度完全相同,并且在同一字符处失败。 XML 的请求长度为 9576 个字符,PHP 发布的 Content-Length 标头为 9615,并且服务在字符 9383 处失败。如果我添加、删除或修改相关字符之前的任何内容(字母“ d"),请求通过。失败的字符在两个请求中都是相同的字母并且位于相同的位置。

尽管这是事实,但第三个失败的请求有 4812 个字符,Content-Length 标头为 4852,并且在字符 3863 处失败。这种情况下的字符不是同一个字符(它是字母“g”),而且不是在同一个 XML 节点内。

如果我向这些请求添加任何内容,甚至从中删除元素,它们都会顺利完成。我不必删除或修改特定元素,只要它出现在反序列化失败的字符之前即可。

有谁知道为什么这些请求会发生超时?对于潜在的解决方法有什么建议吗?

I have a ASP .NET SOAP Service that is being called using PHP's SoapClient class. Generally, the service method that I am calling works, but for a select few cases it consistently fails. When it does fail, the service will timeout after about 90 seconds.

I have traced the root cause of the problem to the ASP .NET service where it is attempting to deserialize the provided XML. In the logs, it appears that the .NET service thinks that the XML is truncated:

System.Xml.XmlException: Unexpected end of file has occurred. The following elements are not closed: ns1:Description, [...], SOAP-ENV:Body, SOAP-ENV:Envelope

System.InvalidOperationException: There is an error in XML document (2, 9383)

In my PHP code, I am logging the XML used in the request by calling $client->__getLastRequest(). The XML that is being provided is valid and absent of any abnormal characters that could break the deserialization.

To make matters stranger, it is not only a single request that fails. I can consistently make three requests fail.

Two of the requests are the exact same length and are failing at the same character. The request length of the XML is 9576 characters, the Content-Length header that is posted by PHP is 9615, and the service is failing on character 9383. If I add, remove, or modify anything before the character in question (the letter "d"), the request goes through. The character that is failing is the same letter and in the same spot at both requests.

Although this is true, the third failing request is 4812 characters, has a Content-Length header of 4852, and is failing on character 3863. The character in this case is not the same character (it's the letter "g") and it's not within the same XML node.

If I add anything to these requests or even remove elements from them, they go through fine. I don't have to remove or modify a particular element as long as it occurs prior to the character where the deserialization is failing.

Does anyone have any idea why this timeout could be happening for these requests? Any suggestions for potential workarounds?

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

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

发布评论

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

评论(1

怪我太投入 2024-12-30 09:15:50

我的解决方法是 - 将 POST 请求中的内容长度设置为比实际 length($request)-1 少一个字符。

感谢您的详细描述 - 我现在已经能够解决我自己的问题了!

My workaround is - set the Content Length in your POST request to be one character less long than it actually is length($request)-1.

Thanks to your detailed description - I have now been able to solve my own problem!

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