如何启用gzip HTTP COM pression在Windows Azure上的动态内容 [英] How to enable gzip HTTP compression on Windows Azure dynamic content

查看:194
本文介绍了如何启用gzip HTTP COM pression在Windows Azure上的动态内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直没有成功启用gzip HTTP COM pression在我的Windows Azure托管WCF RESTful服务只从GET和POST请求返回JSON。

我已经尝试了这么多事情,我会很难列出所有的人,我现在意识到我一直在与矛盾的信息(关于旧版本的天蓝色等),所以认为它最好先用干净的石板!

我与Visual Studio 2008的工作,使用2010年2月工具Visual Studio的。

因此​​,根据以下链接 ..

.. HTTP COM pression现在已经启用。我在下面的页面中使用的意见(网址COM pression建议只)。

http://blog.smarx.com/文章/ IIS-COM pression功能于Windows的蔚蓝

 < urlCom pression doStaticCom pression =真
         doDynamicCom pression =真
         dynamicCom pressionBeforeCache =真
/>

..但我没有得到任何COM pression。它没有帮助,我不知道有什么区别之间的 urlCom pression httpCom pression 。我试图找出,但无济于事!

能,事实上,为Visual Studio工具中的版本的Azure的支持COM pression发布之前,是一个问题?我已阅读的地方,与最新的工具,你可以选择你想要当你发布使用哪个Azure的OS版本...但我不知道这是不是真的,如果是,我找不到在哪里选择。我可以用pre-HTTP启用的版本?

我也试过blowery HTTP COM pression模块,但没有结果。

任何一个是否有关于如何实现这一目标的任何向上的最新建议?即涉及到在Azure操作系统。

当前版本的建议

干杯!

史蒂芬

更新:我编辑了以上code固定在web.config片段类型

更新2:的测试使用下面的答案显示的URL whatsmyip的反应是显示,没有任何COM pression正在返回从我service.svc我的JSON响应,但静态HTML网页被用gzip COM pression返回。关于如何获得JSON响应COM preSS任何意见都会受到欢迎!

更新3:的尝试了JSON响应大于256KB,看看问题是否是由于在下面的评论中提到的JSON响应比这个小。不幸的是,反应仍然未COM pressed。


解决方案

好花了非常很长一段时间......但我终于解决了这一点,我想张贴任何人的答案人谁是挣扎。解决的办法很简单,我已经验证了它确实工作!

编辑ServiceDefinition.csdef中文件包含这在WebRole标记:

 <&启动GT;
      <任务的命令行=EnableCom pression.cmd的ExecutionContext =架空任务类型=简单>< /任务>
    < /启动>

在你的web角色,创建一个文本文件并将其保存为EnableCom pression.cmd

EnableCom pression.cmd应该包含这样的:

 %WINDIR%\\ SYSTEM32 \\ INETSRV \\ appcmd设置配置/部分:urlCom pression / doDynamicCom pression:真/承诺:APPHOST
%WINDIR%\\ SYSTEM32 \\ INETSRV \\ appcmd设置配置-section:system.webServer / httpCom pression /+\"dynamicTypes.[mimeType='application/json;字符集= utf-8',使='真'] /承诺:APPHOST

..这就是它!完成!这使得动态COM pression由网络的作用,我认为我读的地方有一个相当奇怪的MIME类型返回的JSON,所以一定要复制code准确。

I've been trying unsuccessfully to enable gzip HTTP compression on my Windows Azure hosted WCF Restful service which returns JSON only from GET and POST requests.

I have tried so many things that I would have a hard time listing all of them, and I now realise I have been working with conflicting information (regarding old version of azure etc) so think it best to start with a clean slate!

I am working with Visual Studio 2008, using the February 2010 tools for Visual Studio.

So, according to the following link..

.. HTTP compression has now been enabled. I've used the advice at the following page (the URL compression advice only)..

http://blog.smarx.com/posts/iis-compression-in-windows-azure

<urlCompression doStaticCompression="true" 
         doDynamicCompression="true"
         dynamicCompressionBeforeCache="true" 
/>

.. but I get no compression. It doesn't help that I don't know what the difference is between urlCompression and httpCompression. I've tried to find out but to no avail!

Could, the fact that the tools for Visual Studio were released before the version of Azure which supports compression, be a problem? I have read somewhere that, with the latest tools, you can choose which version of Azure OS you want to use when you publish ... but I don't know if that's true, and if it is, I can't find where to choose. Could I be using a pre-http enabled version?

I've also tried blowery http compression module, but no results.

Does any one have any up-to-date advice on how to achieve this? i.e. advice that relates to the current version of the Azure OS.

Cheers!

Steven

Update: I edited the above code to fix a type in the web.config snippet.

Update 2: Testing the responses using the whatsmyip URL shown in the answer below is showing that my JSON responses from my service.svc are being returned without any compression, but static HTML pages ARE being returned with gzip compression. Any advice on how to get the JSON responses to compress will be gratefully received!

Update 3: Tried a JSON response larger than 256KB to see if the problem was due to the JSON response being smaller than this as mentioned in comments below. Unfortunately the response is still un-compressed.

解决方案

Well it took a very long time ... but I have finally solved this, and I want to post the answer for anyone else who is struggling. The solution is very simple and I've verified that it does definitely work!!

Edit your ServiceDefinition.csdef file to contain this in the WebRole tag:

    <Startup>
      <Task commandLine="EnableCompression.cmd" executionContext="elevated" taskType="simple"></Task>
    </Startup>

In your web-role, create a text file and save it as "EnableCompression.cmd"

EnableCompression.cmd should contain this:

%windir%\system32\inetsrv\appcmd set config /section:urlCompression /doDynamicCompression:True /commit:apphost
%windir%\system32\inetsrv\appcmd set config  -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/json; charset=utf-8',enabled='True']" /commit:apphost

.. and that's it! Done! This enables dynamic compression for the json returned by the web-role, which I think I read somewhere has a rather odd mime type, so make sure you copy the code exactly.

这篇关于如何启用gzip HTTP COM pression在Windows Azure上的动态内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆