简体   繁体   English

Web服务客户端和压缩

[英]Webservice Client and Compression

I have Managed to Setup II7 with Gzip Compression . 我已经设法使用Gzip Compression设置II7。

I can check via web sniffer that my asmx web service encoding is Gzip but how to i enable gzip Compression on my C# Client , i am using the Web Service is Service reference in my application. 我可以通过网络嗅探器检查我的asmx Web服务编码为Gzip,但是如何在C#Client上启用gzip压缩,我在应用程序中使用Web Service is Service参考。

Actually i am trying to send large amount of data , 10k objects of array so Compression with be great effect on bw. 实际上,我正在尝试发送大量数据,数组的1万个对象,因此压缩对bw影响很大。

but how do I enable Compression on my C# Client. 但是如何在C#客户端上启用压缩。

i am trying to see that many people sees same problem but there nothing clear answer some says use third party tools or some says about custom headers etc etc . 我试图看到很多人看到相同的问题,但没有明确的答案,有人说使用第三方工具,或者有人说使用自定义标题等。

is not there any proper way , built in to consume Compressed web service 没有任何内置使用压缩Web服务的正确方法

As @Igby Largeman pointed out, you can use your IIS7 to enable the compression on the server, but this is not enough. 正如@Igby Largeman指出的那样,您可以使用IIS7在服务器上启用压缩,但这还不够。
The main idea is to set the headers on the client side and server side: 主要思想是在客户端服务器端设置标头:

Client : 客户

Accept-Encoding = "gzip, deflate";

You can achieve this by code: 您可以通过代码来实现:

var request = HttpWebRequest.Create("http://foofoo");
request.Headers["Accept"] = "application/json";
request.Headers["Accept-Encoding"] = "gzip, deflate";

or 要么

var request = HttpWebRequest.Create("http://foofoo");
request.AutomaticDecompression = DecompressionMethods.GZip |  
  DecompressionMethods.Deflate;

If you use some WCF client, and not the HttpWebRequest , you should use custom inspector and dispatcher, like in this article : 如果您使用一些WCF客户端,而不是HttpWebRequest ,则应使用自定义检查器和调度程序,如本文所述

So I used a message inspector implementing IClientMessageInspector and IDispatchMessageInspector to automatically set the AcceptEncoding and ContentEncoding http headers. 因此,我使用了实现IClientMessageInspectorIDispatchMessageInspector的消息检查器来自动设置AcceptEncodingContentEncoding http标头。

This was working perfectly but I could not achieve to decompress the response on the server by first detecting the ContentEncoding header thus I used the work around to first try to decompress it and if it fails just try to process the request as normal. 这是完美的工作,但我无法通过首先检测ContentEncoding标头来在服务器上解压缩响应,因此我使用了变通方法来首先尝试对它进行解压缩,如果失败,则尝试尝试正常处理请求。

I also did this in the client pipeline and this also works. 我也在客户端管道中做到了这一点,这也行得通。

Server : 服务器

// This is the nearly same thing after all
Content-Encoding = "gzip" OR Content-Encoding = "deflate"

To do this on the Server side, you should enable httpCompression in the IIS. 要在服务器端执行此操作,应在IIS中启用httpCompression。
I think you should check the original article to get this work 我认为您应该查看原始文章才能完成这项工作

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

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