【问题标题】:How to perform test to check whether WCF Response is compressed with httpCompression on IIS7+如何执行测试以检查 WCF 响应是否在 IIS7+ 上使用 httpCompression 进行压缩
【发布时间】:2015-08-21 16:58:39
【问题描述】:

我正在 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) 使用 telnet 模拟请求并查看您的数据是否可读,或 2) 使用数据包嗅探器并检查您的 TCP 包内容。
  • @norbert van noblemen 我该怎么做?你能给我一些文章或资源吗?我以前没做过

标签: wcf iis-express http-compression


【解决方案1】:

我使用Teleric Fiddler 检查是否发生压缩。我已经尝试过以下事情来检查压缩应该在哪些情况下工作以及在哪些情况下不工作。提琴手并没有让我失望。

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

【讨论】:

    猜你喜欢
    • 2011-02-12
    • 1970-01-01
    • 2010-10-21
    • 2013-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-17
    相关资源
    最近更新 更多