【发布时间】:2011-02-12 09:09:03
【问题描述】:
就我而言,每个人都在编辑 2 中解决了这个问题。虽然这只是问题的 IIS 方面的部分解决方案,但它正是我所寻找的。p>
因此,我将把我的查询添加到有关该主题的大量问题中。
我正在尝试对来自 WCF 服务的大型肥皂响应启用 GZip 压缩。到目前为止,我已经按照here 和其他各种地方的说明在 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 来添加 Accept-Encoding: gzip, deflate 到我客户的 HttpRequests。以下是取自 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),都不会发生压缩。我看过this post,但没有遇到他描述的异常,所以我没有尝试过他提出的CodeProject实现。此外,我还看到了很多其他的实现,它们应该可以让它工作,但无法理解它们(例如,msdn's GZip encoder)。为什么我需要实现编码器或代码项目解决方案? IIS 不应该负责压缩吗?
那么我还需要做什么才能让它发挥作用?
乔尼
编辑: 我认为 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 至少压缩了来自服务的肥皂消息(尽管我现在在客户端上遇到了一个异常,但是已经发布了几个解决方案)。 问题是我的服务器上没有安装 DynamicCompressionModule。实际上,对我来说,“安装”它意味着只需将这一行添加到 applicationHost.config 的部分:
<add name="DynamicCompressionModule" image="%windir%\System32\inetsrv\compdyn.dll" />
(假设 dll 存在于该目录中,在我的情况下它确实存在。) 然后通过 IIS7 的 Modules 部分为网站或服务器添加模块。
【问题讨论】:
-
可能是一个愚蠢的问题,但它欺骗了我一段时间 - 你怎么知道压缩没有发生?如果是因为您没有在 Fiddler 中看到它,请注意 Fiddler 会自动解压缩,除非您告诉它不要这样做。
标签: wcf iis-7 http-compression