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

时间:2015-06-06 23:33:54

标签: wcf iis-express http-compression

我正在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控制台应用程序。应用程序服务和客户端都在同一台机器上运行。

1 个答案:

答案 0 :(得分:0)

我用Teleric Fiddler检查压缩是否发生。我已经尝试过以下方法来检查哪种情况下压缩应该起作用,哪些不起作用。而提琴手并没有让我失望。

  1. <urlCompression doDynamicCompression="false" />不应压缩动态响应时。
  2. <urlCompression doDynamicCompression="true" />时,除非设置了<httpTransport decompressEnabled="false" />,否则它应该在任何情况下进行压缩。 basicHttpBinding总是向服务器发送Accept-encoding="gzip,deflat",要禁用压缩,我们需要创建customBinding并将上面的属性设置为false。