gpt4 book ai didi

wcf - 使用 IIS7 上托管的 WCF 进行 GZip 压缩

转载 作者:行者123 更新时间:2023-12-03 11:01:05 26 4
gpt4 key购买 nike

每个人,就我而言,这个问题在 EDIT 2 中得到了解答。虽然这只是问题的 IIS 方面的部分解决方案,但它正是我所寻找的。

因此,我将把我的查询添加到有关该主题的大量问题中。

我正在尝试对来自 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 的请求 header 示例:
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 绑定(bind)可能值得发布,但我不确定它们是否相关(这些来自客户端):
<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 的模块部分为网站或服务器添加模块。

最佳答案

尝试添加 'application/soap+xml; charset=utf-8' 作为 applicationHost 中的动态类型。添加这个字符集部分帮助我为来自我的 http 处理程序的一些 JSON 响应启用压缩。

关于wcf - 使用 IIS7 上托管的 WCF 进行 GZip 压缩,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2713203/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com