如何执行测试以检查 WCF 响应是否在 IIS7+ 上使用 httpCompression 压缩

How to perform test to check whether WCF Response is compressed with httpCompression on IIS7+

我正在 IIS 8 Express 上托管的 .NET 4.5 中构建测试 WCF 服务 (PersonService)。我还在 IIS 上安装了动态压缩。据我所知,默认情况下启用 WCF 4.0 向前压缩。为了在服务中启用 httpCompression,我更新了 Web.Config 如下:

<?xml version="1.0"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <system.webServer>
    <httpCompression>
      <dynamicTypes>
        <add mimeType="application/soap+xml" enabled="true"/>
        <add mimeType="application/soap+xml; charset=utf-8" enabled="true"/>
        <add mimeType="application/soap+xml; charset=ISO-8895-1" enabled="true"/>
      </dynamicTypes>
    </httpCompression>
    <urlCompression doDynamicCompression="true" doStaticCompression="true"/>
  </system.webServer>
   <system.serviceModel>
    <services>
      <service name="PersonServiceLibirary.PersonService">
        <endpoint address="" binding="basicHttpBinding" contract="PersonServiceLibirary.IPersonService">
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
     <bindings>
       <basicHttpBinding>
         <binding maxBufferPoolSize="524288000" maxBufferSize="524288000" maxReceivedMessageSize="524288000">

         </binding>
       </basicHttpBinding>
     </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, 
          set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
          <!-- To receive exception details in faults for debugging purposes, 
          set the value below to true.  Set to false before deployment 
          to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

</configuration>

问题:我想验证压缩是否真的发生了。如何在发送之前验证响应是否在服务器端被压缩,以及它是否在客户端被解压缩。

注意:我的客户端应用程序也是使用上述服务的 .NET 控制台应用程序。应用程序服务和客户端 运行 在同一台机器上。

我用 Teleric Fiddler 检查压缩是否发生。我尝试了以下操作来检查压缩在哪些情况下应该起作用,在什么情况下不起作用。而fiddler也没有让我失望

  1. <urlCompression doDynamicCompression="false" />时不应该压缩动态响应。
  2. <urlCompression doDynamicCompression="true" />时,除非设置<httpTransport decompressEnabled="false" />,否则无论如何都应该压缩。 basicHttpBinding 总是发送 Accept-encoding="gzip,deflat" 到服务器,要禁用压缩,我们需要创建 customBinding 并在上面设置 属性 false。