jon*_*iba 24 wcf iis-7 http-compression
每个人,就我而言,这个问题都是在EDIT 2中进行的.尽管这只是问题的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>
Run Code Online (Sandbox Code Playgroud)
并且:
<urlCompression doDynamicCompression="true" doStaticCompression="true" />
Run Code Online (Sandbox Code Playgroud)
虽然我不清楚为什么需要这样做.
为了以防万一,在那里扔了一些额外的哑剧类型.我已经实现了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
Run Code Online (Sandbox Code Playgroud)
现在,这不起作用.无论消息大小如何(尝试高达1.5Mb),都不会发生压缩.我看过这篇文章,但没有像他描述的那样遇到异常,所以我没有尝试过他提出的CodeProject实现.此外,我已经看到许多其他实现应该让它工作,但无法理解它们(例如,msdn的GZip编码器).为什么我需要实现编码器或代码项目解决方案?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>
Run Code Online (Sandbox Code Playgroud)
编辑2:对于这个神秘局势中的其他任何人,我有一个部分解决方案.即,我已经获得IIS7至少压缩来自服务的soap消息(虽然我现在在客户端上获得了一个例外,但是为此已经发布了几个解决方案).问题是我的服务器上没有安装DynamicCompressionModule.对我来说,实际上"安装"它意味着只需将此行添加到applicationHost.config的部分:
<add name="DynamicCompressionModule" image="%windir%\System32\inetsrv\compdyn.dll" />
Run Code Online (Sandbox Code Playgroud)
(假设dll存在于该目录中,在我的情况下它确实存在.)然后通过IIS7的模块部分为网站或服务器添加模块.
Mar*_*rko 14
尝试添加'application/soap + xml; charset = utf-8'作为applicationHost中的动态类型.添加这个charset部分帮助我从我的http处理程序启用了一些JSON响应的压缩.
Sim*_*ver 10
这与@marko的答案基本相同 - 详细步骤.每次我再次访问时,这都是一个令人沮丧的话题,所以我想概述一下我需要做的一切才能让它工作.
首先,您需要在IIS7上使用.NET 4.这是因为直到.NET 4,WCF才能自动解压缩gzip流.有关详细信息,请参阅" WCF 4中的新内容 "(反馈中的一些有用的评论).
通过允许客户端使用gzip自动协商或压缩压缩流然后自动解压缩它们,我们使用HTTP时更容易.
其次,请确保已在IIS中启用动态压缩模块.您可能需要转到"程序和功能"进行安装.确保您为相关的Web应用程序启用了它 - 因为它不是全局设置.
现在WPF使用MIME类型application/soap+xml; charset=utf-8
进行HTTP传输(至少使用wsHttpBinding).默认情况下,这不是动态类型,因此需要将其添加到applicationHost.config
文件中.
只需在服务器上编辑此文件:C:\ Windows\System32\Inetsrv\Config\applicationHost.config
在<dynamicTypes>
节点中添加以下行(BEFORE / LINE):
<add mimeType="application/soap+xml; charset=utf-8" enabled="true" />
Run Code Online (Sandbox Code Playgroud)
重启IIS
归档时间: |
|
查看次数: |
11772 次 |
最近记录: |