GZip compression with WCF hosted on IIS7

前端 未结 8 2262
难免孤独
难免孤独 2020-12-13 07:11

Everyone, as far as I\'m concerned the question is ansered in EDIT 2. Although it\'s only a partial solution to the IIS side of the problem, it\'s what I was looking for.

8条回答
  •  天涯浪人
    2020-12-13 08:06

    A lot of people are struggling with enabling IIS level compression for WCF Services. Mainly people are struggling with wsHttpBinding, where basicHttpBinding compresses out of the box if dynamic compression is enabled in IIS. I am not going to go into how to enable dynamic compression because it's covered in many different posts, just search for "iis compression application/soap+xml". As previously stated, if you've configured everything properly you should be able to see WCF responses compressed with Content-Encoding: gzip in response header. I suggest using Fiddler to track your request/response. This was my (any many others) experience with basicHttpBinding. The question then becomes why does it not work with wsHttpBinding? Undoubtedly you've already read that it's because the Content-Type is different between those two bindings. basicHttpBinding uses Content-Type: text/xml; charset=utf-8 where wsHttpBinding uses Content-Type: application/soap+xml; charset=utf-8. The former is covered by the default IIS applicationHost.config setting under dynamicTypes. The latter is not. You probably read that you need to add this additional mimeType and restart IIS to fix this. This works for some people, however it does not for many. Some declare that it's simply not compatible with wsHttpBinding. Here is the problem. There are potentially two applicationHost.config files:

    C:\Windows\System32\inetsrv\config
    C:\Windows\SysWOW64\inetsrv\Config
    

    System32 is the 64bit one, and is the one used by your installation of IIS. This is also the one you've modified to add the additional mimeType to, or so you thought!

    cannot manually edit applicationhost.config - MUST READ

    As it turns out, if you use a 32bit application such as Notepad++, what you end up modifying is the file in the SysWOW64 folder. This is completely transparent to you. If you use regular Notepad application you'll notice that the mimeType you've added is actually not in the file that is located in the System32 folder, it was magically added to the SysWOW64 folder, even though you've never actually browsed to that folder to begin with. Hopefully this saves you many hours of grief.

提交回复
热议问题