简体   繁体   English

WCF gzip压缩?

[英]WCF gzip compression?

I need to compress my WCF response. 我需要压缩WCF响应。 After few google search, I found that 经过几次Google搜索,我发现

  • I need to enable compression on iis7 我需要在iis7上启用压缩
  • I need to add some entry in the applicationhost.config. 我需要在applicationhost.config中添加一些条目。

My wcf is hosted on discountasp.net. 我的wcf托管在discountasp.net上。 In the control panel, I didn't find any option to enable compression. 在控制面板中,我没有找到启用压缩的任何选项。 And also, the applicationhost.config is located in the 'C:\\Windows\\System32\\Inetsrv\\Config\\applicationHost.config' directory. 而且,applicationhost.config位于“ C:\\ Windows \\ System32 \\ Inetsrv \\ Config \\ applicationHost.config”目录中。

And in the shared hosting environment, I dont have access to this directory. 在共享主机环境中,我无权访问此目录。

My question is, if my above observation is correct, how do I get it done in the shared hosting?? 我的问题是,如果我的上述观察是正确的,如何在共享主机中完成?

edit: 编辑:

I have found something here: enter link description here 我在这里找到了一些东西:在这里输入链接描述

I tried this with no luck. 我没有运气尝试过。 In the response header in Fiddler, I dont see any compression. 在Fiddler的响应标头中,我没有看到任何压缩。

One alternative is to implement an HttpModule that would intercept the response based on the content type and compress the output on the fly, using the GZipStream class. 一种替代方法是使用GZipStream类实现一个HttpModule,该模块将根据内容类型截取响应并动态压缩输出。

This post has a complete example and I've used this method successfully in production. 这篇文章有一个完整的示例,我已经在生产中成功使用了此方法。 All you need to do is change your Web.config to register the http module: 您需要做的就是更改您的Web.config来注册http模块:

<httpModules>
    <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    <add name="JsonCompressionModule" type="JsonCompressionModule"/>
</httpModules>

The example does it for JSON responses but there's nothing that stops you from doing the same thing for XML responses. 该示例对JSON响应执行此操作,但是没有什么可以阻止您对XML响应执行相同的操作。

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

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