How to enable IIS compression for WCF services?

别来无恙 提交于 2019-11-28 09:18:51
Arjan van der Meer

I had the same problem; .aspx pages were compressed but WCF content wasn't. It has to do with the content type returned by the WCF service, which got appended to the mime-type.

I got it to work with the following section in the ApplicationHost.config:

<dynamicTypes>
    <add mimeType="text/*" enabled="true" />
    <add mimeType="message/*" enabled="true" />
    <add mimeType="application/*" enabled="true" />
    <add mimeType="*/*" enabled="false" />
</dynamicTypes>

Here's what I did (most of the same steps as mentioned already):

  • Install the Dynamic Compression Role Service for IIS role
  • Enable Dynamic Content Compression for the website that you use to host the WCF service
  • Open %SystemRoot%\system32\inetsrv\config\applicationhost.config and add the relevant content type to the section of the
  • After this it still didn't work.
  • I checked the data with Firefox' Tamper Data and noticed the content type returned was actually "application/xml; charset=utf-8".
  • After adding the complete content type, including the "; charset=utf-8" to the section, it worked:
<add mimeType="application/xml; charset=utf-8" enabled="true" />

As I felt that the character set encoding should not be determining if the compression works or not, I ended up letting IIS compress all application/* content types.

Perhaps it depends on the specific WCF service setup you are using, but for the applications I have used it in (all were mixed access for both .NET applications and Silverlight pages), the generated WCF client class contained an EnableDecompression property that can be set to true. After that my Winforms apps send the correct headers and the webservice communication is correctly compressed.

It seems you can enable Dynamic Compression in IIS via the GUI or CLI.

This article shows you both ways:

http://www.hanselman.com/blog/EnablingDynamicCompressionGzipDeflateForWCFDataFeedsODataAndOtherCustomServicesInIIS7.aspx

I found the GUI way easy. The article shows you how to confirm it is working with Fiddler.

Cheers!

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!