简体   繁体   English

使用动态压缩对IIS7进行异步Web服务调用不起作用

[英]Async Web Service calls to IIS7 with Dynamic Compression don't work

We have some ASP.NET Web Services that fail under this perfect storm of conditions: 在这种完美的条件下,我们有一些ASP.NET Web服务失败:

  1. IIS7 IIS7
  2. Dynamic Compression is turned on 动态压缩已打开
  3. Web Service call is Asynchronous Web服务调用是异步的

If it is IIS 6, or we turn Dynamic Compression off or call the web service synchronously, it works fine. 如果是IIS 6,或者我们关闭了动态压缩功能或同步调用了Web服务,则它可以正常工作。

It fails in the call to SoapHttpClientProtocol.EndInvoke(IAsyncResult asyncResult) with an 'Unexpected end of file' error. 它在对SoapHttpClientProtocol.EndInvoke(IAsyncResult asyncResult)的调用中失败,并出现“意外的文件结尾”错误。

Using Fiddler, I see that the response from IIS 6 has a transfer-encoding of 'chunked' and no content-length. 使用Fiddler,我看到来自IIS 6的响应具有“块式”的传输编码,并且没有内容长度。 The response from IIS 7 is NOT chunked and has a content-length. IIS 7的响应未分块,并且具有内容长度。 The end of file error occurs 1 character past the content length. 文件结束错误发生在内容长度之后的1个字符处。

If I intercept the message in Fiddler and change it to chunked, there is no error. 如果我在Fiddler中拦截消息并将其更改为成块,则不会出现错误。 The answer could be to change it to chunked in IIS 7 (which I've tried to do and failed), but I don't feel like I should have to do this: I think it should just work! 答案可能是将其更改为IIS 7中的分块(我尝试这样做并失败了),但是我觉得我不应该这样做:我认为它应该可以工作!

I had to open an MSDN support ticket with Microsoft for this one, but got my answer. 我必须为此与Microsoft开一张MSDN支持票,但得到了答案。

The answer here is a simple client-side solution. 答案是一个简单的客户端解决方案。 My previous WebRequest method looked like this: 我以前的WebRequest方法看起来像这样:

protected override WebRequest GetWebRequest(Uri uri)
{
    var request = base.GetWebRequest(uri);
    request.Headers.Add("Accept-Encoding", "gzip");
    return request;
}

The better way is this: 更好的方法是这样的:

protected override WebRequest GetWebRequest(Uri uri)
{
    var request = (HttpWebRequest) base.GetWebRequest(uri);
    request.AutomaticDecompression = DecompressionMethods.GZip;
    return request;
}

I'm not entirely sure why this works: The headers on the request and response are exactly the same, but the client seems to be able to manage the response it gets back. 我不完全确定为什么这样做:请求和响应的标头完全相同,但是客户端似乎能够管理返回的响应。

This seems to work with both IIS6 and IIS7, even though the IIS6 response is chunked and the IIS7 one isn't. 即使IIS6响应已分块,而IIS7却没有,但这似乎对IIS6和IIS7都适用。 If anyone can help explain exactly why this works, it might be helpful to the community. 如果有人可以帮助您确切解释其工作原理,则可能对社区有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM