WSE 3.0 设置内容类型

发布于 2024-07-23 03:19:50 字数 612 浏览 4 评论 0原文

我有一个简单的问题要问你,但我似乎无法理解。

情况如下:

  • 我们使用 WSE 3 创建并向 Web 服务发送请求。Web
  • 服务是用 Java 编写的。

大多数事情都很好,但我似乎无法对 WebResuest 或 WebResponse 的 ContentType 产生影响,这会导致一些问题。

我不断收到的错误消息如下:

客户端发现响应内容类型为“application/xop+xml;type="text/xml;charset=utf-8"”,但预期为“text/xml”。 请求失败并显示错误消息: ....

在错误消息的详细信息中,它包含对来自服务器的调用的响应,并且它正确通过。 显然,目前情况并不好,因为它遇到了异常:)。

那么,如何设置响应的预期内容类型?

如果我是正确的,WSE 3.0 中的请求和响应必须具有相同的 ContentType。 所以我想我会尝试将 request.Headers[HttpRequestHeader.ContentType] 设置为预期的值,但没有运气。 (另外,我可以在很多地方设置 HttpWebRequest 的内容类型,但它们似乎都不起作用)

I've a simple question, for you, that I just can't seem to get my head around.

The situation is the following:

  • We create and send a request to a web service, using WSE 3.
  • The web service is written in Java.

Most of the things are fine, but I can't seem to have an impact on the ContentType of either the WebResuest or WebResponse and that's causing some problems.

The errormessage I keep getting is the following:

Client found a response content type of ' application/xop+xml;type="text/xml; charset=utf-8" ' but expected 'text/xml'.
The request failed with the error message: ....

In the details of the error message it has the response to our call from the server and it's coming through properly.
Obviously it's not good as it is at the moment as it's coming through an exception :).

So, how could I set the expected content type for the response?

If I'm correct, the Request and the Response in WSE 3.0 has to have the same ContentType. So I thought I would try to set the request.Headers[HttpRequestHeader.ContentType] to the expected one, but with no luck. (also, I can set the HttpWebRequest's contenttype in quite a few places, but none of them seem to do the trick)

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

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

发布评论

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

评论(1

中二柚 2024-07-30 03:19:50

幸运的是,这个问题已经解决了,所以这里是供将来参考的解决方案:

我们的客户端继承自WebServicesClientProtocol类,其中有一个名为GetWebResponse(..)的方法。
简单地覆盖该方法并更改响应的 ContentType 似乎对我们有用。

    protected override WebResponse GetWebResponse(System.Net.WebRequest request)
    {
        WebResponse response = base.GetWebResponse(request);
        response.Headers[HttpResponseHeader.ContentType] = "text/xml";
        return response;
    }

This has been solved luckily, so here's the solution for future reference:

Our client inherits from the WebServicesClientProtocol class, in which there's a method called GetWebResponse(..).
Simply overriding that method and changing the ContentType of the Response seemed to work out for us.

    protected override WebResponse GetWebResponse(System.Net.WebRequest request)
    {
        WebResponse response = base.GetWebResponse(request);
        response.Headers[HttpResponseHeader.ContentType] = "text/xml";
        return response;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文