【发布时间】:2012-04-12 14:31:56
【问题描述】:
我有一个托管在 IIS7.5 上的 .NET 3.5 Web 服务。
我有一个连接到这个网络服务的客户端应用程序。
我更改(在客户端应用程序中)httpWebRequest.Create 方法为 GZip 添加自动解压缩,但它不起作用
WebRequest IWebRequestCreate.Create(Uri uri)
{
HttpWebRequest httpWebRequest =
Activator.CreateInstance(
typeof(HttpWebRequest),
BindingFlags.CreateInstance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,
null,
new object[] { uri, null },
null) as HttpWebRequest;
if (httpWebRequest == null)
return null;
httpWebRequest.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
httpWebRequest.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
return httpWebRequest;
}
这样请求发送正确,答案用gzip编码(我从Fiddler看到的),但是出现异常:
Response is not wellformed XML
(我认为客户端没有解码答案)
如果我删除这一行,如 MSDN 文档中所述
httpWebRequest.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
答案不是 GZip 编码的(并且在请求中没有 ACCEPT-ENCODING 标头)
【问题讨论】:
-
IIS 应该可以为任何托管服务添加压缩支持。没有办法通过自定义编码实现GZip压缩。
-
是的.. 好的.. 我如何在 WCF Web 服务中使用 GZip 压缩?因为我要传输大量的文本数据..
-
大约 2-3 年前,我经历了这整个痛苦的过程。一直试图找到我找到的解决方案,但到目前为止还没有运气。同时 +1。
-
更新:我找到了二进制文件,并设法通过 Reflector 查看了代码。就我而言,我只设置了
AutomaticDecompression,没有别的。将查看是否涉及其他代码。 -
我已经浪费了很多时间来尝试实现它,但我没有成功。好吧,我们已经在 C# 服务器和 Java 客户端中实现了自定义数据压缩。
标签: c# wcf web-services gzip