0

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)

4

1 回答 1

2

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

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

    protected override WebResponse GetWebResponse(System.Net.WebRequest request)
    {
        WebResponse response = base.GetWebResponse(request);
        response.Headers[HttpResponseHeader.ContentType] = "text/xml";
        return response;
    }
于 2009-06-03T10:04:06.057 回答