如何修复在 Java 客户端中导致 UnsupportedMediaException 的 .NET Webservice 超时?

发布于 2024-07-09 11:48:26 字数 672 浏览 5 评论 0原文

我目前有一个 .net SOAP Web 服务,在我使用设置的请求上有一个超时,

Server.ScriptTimeout = TIME_OUT;

然后让 java 客户端调用所述 Web 服务。 然而,当达到超时时,我得到了这个异常:

Exception in thread "Thread-9" com.sun.xml.ws.server.UnsupportedMediaException: Unsupported Content-Type: text/html; charset=utf-8 Supported ones are: [text/xml]

发生的情况是,Web 服务返回一个带有 http 超时代码的 html 错误页面(我认为是 503?),这是我的 Java 代码(使用 WSDLimport 生成的)所不希望的。

现在我可以在客户端捕获错误 UnsupportedMediaException 并尝试将其转换为更有意义的内容,但我更愿意在 Web 服务端发送更具体的超时异常。 无论如何,.net Web 服务中是否有在超时发生时发出更好的异常的方法,或者有其他方法可以更好地处理这种情况?

编辑:
我正在使用 glassfish 2 发行版中的 WSDLImport。

I currently have a .net SOAP web service with a timeout on the request that I set using

Server.ScriptTimeout = TIME_OUT;

I then have java client calling said web service. However when the timeout is reached I get this exception:

Exception in thread "Thread-9" com.sun.xml.ws.server.UnsupportedMediaException: Unsupported Content-Type: text/html; charset=utf-8 Supported ones are: [text/xml]

What is happening is that the web service returns an html error page with the http timeout code (503 I think?), which my Java code (generated using WSDLimport) doesn't expect.

Now I could catch the error UnsupportedMediaException on the client and attempt to translate it into something more meaningful, but I would prefer to send out a more specific timeout exception on the web service side. Is there anyway in a .net web service to send out a better exception when a timeout occurs, or any other way to handle this situation better?

EDIT:
I am using the WSDLImport from the glassfish 2 distribution.

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

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

发布评论

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

评论(2

数理化全能战士 2024-07-16 11:48:26

这是 Sun JAX-WS 的已知问题堆。

作为参考,HTTP 500 代码实际上意味着服务器出现内部服务器错误。 我不确定为什么 .NET 发送该消息而不是 HTTP 503 Service Unavailable。

This is a known issue with Sun's JAX-WS stack.

For reference, the HTTP 500 code actually means that the server had an Internal Server Error. I'm not sure why .NET sends that rather than HTTP 503 Service Unavailable.

阪姬 2024-07-16 11:48:26

您可以将 Web 服务设为异步。 然后在 BeginMyMethod 中启动一个带有超时的计时器,并在 EndMyMethod 方法中抛出自定义异常。 它将被包装在 SOAP 异常中并按原样发送到客户端。

You can make your webservice asynchronous. Then start a timer with your timeout in the BeginMyMethod, and throw custom exception in your EndMyMethod method. It will be wrapped in SOAP exception and sent to the client as such.

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