How to enable IIS compression for WCF services?

后端 未结 4 1280
南笙
南笙 2020-12-09 21:02

I currently use a custom gzip encoder for my WCF service. I want to replace it with the built-in IIS 7 compression if that is possible. I can\'t find info online on how to t

4条回答
  •  半阙折子戏
    2020-12-09 21:50

    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:

    
        
        
        
        
    
    

    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:
    
    

    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.

提交回复
热议问题