我认为,对于这个问题,我的回答在第二次编辑中得到了解答。虽然它只是该问题在IIS方面的部分解决方案,但这正是我所期望的。
因此,我将把我的疑问添加到关于这个主题的众多问题之中。
我正在尝试启用WCF服务中大型SOAP响应的GZip压缩。到目前为止,我已经按照这里和其他地方的各种指示启用了IIS上的动态压缩。下面是来自applicationHost.config的dynamicTypes部分:
<dynamicTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="application/atom+xml" enabled="true" />
<add mimeType="application/xaml+xml" enabled="true" />
<add mimeType="application/xop+xml" enabled="true" />
<add mimeType="application/soap+xml" enabled="true" />
<add mimeType="*/*" enabled="false" />
</dynamicTypes>
还有:
<urlCompression doDynamicCompression="true" doStaticCompression="true" />
虽然我不是很清楚为什么需要这样做。
为了保险起见,我在那里添加了一些额外的MIME类型。我实现了IClientMessageInspector接口,以向客户端的Http请求添加Accept-Encoding:gzip、deflate。以下是从fiddler中获取的请求头示例:
POST http://[omitted]/TestMtomService/TextService.svc HTTP/1.1
Content-Type: application/soap+xml; charset=utf-8
Accept-Encoding: gzip, deflate
Host: [omitted]
Content-Length: 542
Expect: 100-continue
现在,这并不起作用。无论消息的大小如何(已尝试了高达1.5Mb),都没有进行压缩。我看过这篇帖子,但没有遇到他所描述的异常,因此我没有尝试他提出的CodeProject实现。而且我看到了很多其他的实现,它们应该可以让这个工作,但是无法理解它们(例如,msdn的GZip编码器)。为什么我需要实现编码器或代码项目解决方案?难道IIS不能处理压缩吗?那么,我还需要做什么才能让它起作用呢?
Joni
编辑: 我认为WCF绑定可能值得发布,尽管我不确定它们是否相关(这些来自客户端):
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WsTextBinding" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false"
transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="5000000" maxReceivedMessageSize="5000000"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="5000000"
maxArrayLength="5000000" maxBytesPerRead="5000000" maxNameTableCharCount="5000000" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
<message clientCredentialType="None" negotiateServiceCredential="false"
algorithmSuite="Default" establishSecurityContext="false" />
</security>
<client>
<endpoint address="http://[omitted]/TestMtomService/TextService.svc"
binding="wsHttpBinding" bindingConfiguration="WsTextBinding" behaviorConfiguration="GzipCompressionBehavior"
contract="TestMtomModel.ICustomerService" name="WsTextEndpoint">
</endpoint>
</client>
<behaviors>
<endpointBehaviors>
<behavior name="GzipCompressionBehavior">
<gzipCompression />
</behavior>
</endpointBehaviors>
</behaviors>
<extensions>
<behaviorExtensions>
<add name="gzipCompression"
type="TestMtomModel.Behavior.GzipCompressionBehaviorExtensionElement, TestMtomModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</behaviorExtensions>
</extensions>
</binding>
</wsHttpBinding>
</bindings>
编辑2: 对于其他处于这种神秘情况中的人,我有一个部分解决方案。也就是说,我已经让IIS7至少压缩了来自服务的soap消息(虽然现在客户端出现了异常,但已经有几个解决方案发布)。 问题在于我的服务器上没有安装DynamicCompressionModule。对于我来说,“安装”它实际上意味着将以下行添加到applicationHost.config的“section”中:
<add name="DynamicCompressionModule" image="%windir%\System32\inetsrv\compdyn.dll" />
(假设dll文件存在于该目录中,在我的情况下它确实存在。) 然后通过IIS7的网站或服务器的模块部分添加该模块。