使用 IIS7 上托管的 WCF 进行 GZip 压缩 [英] GZip compression with WCF hosted on IIS7

查看:21
本文介绍了使用 IIS7 上托管的 WCF 进行 GZip 压缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就我而言,每个人都在编辑 2 中解决了这个问题.虽然这只是问题的 IIS 方面的部分解决方案,但它正是我所寻找的.<小时>

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

我正在尝试对来自 WCF 服务的大型肥皂响应启用 GZip 压缩.到目前为止,我已经按照 here 和在 IIS 上启用动态压缩的各种其他地方.这是我在 applicationHost.config 中的 dynamicTypes 部分:

<dynamicTypes><添加 mimeType="text/*" 启用="true"/><添加 mimeType="message/*" enabled="true"/><添加 mimeType="application/x-javascript" enabled="true"/><添加 mimeType="application/atom+xml" enabled="true"/><添加 mimeType="application/xaml+xml" enabled="true"/><添加 mimeType="application/xop+xml" enabled="true"/><添加 mimeType="application/soap+xml" enabled="true"/><添加 mimeType="*/*" 启用="false"/></dynamicTypes>

还有:

<urlCompression doDynamicCompression="true" doStaticCompression="true"/>

虽然我不太清楚为什么需要这样做.

为了以防万一,在其中添加了一些额外的 mime 类型.我已经实现了 IClientMessageInspector 来添加 Accept-Encoding: gzip, deflate 到我客户的 HttpRequests.以下是取自 fiddler 的请求标头示例:

POST http://[省略]/TestMtomService/TextService.svc HTTP/1.1内容类型:application/soap+xml;字符集=utf-8接受编码:gzip,放气主持人:[略]内容长度:542期望:100-继续

现在,这行不通.无论消息大小如何(尝试最大为 1.5Mb),都不会发生压缩.我看过 这篇文章,但没有遇到异常他描述,所以我没有尝试过他提出的 CodeProject 实现.此外,我还看到了很多其他的实现,它们应该可以让它工作,但无法理解它们(例如,msdn 的 GZip 编码器).为什么我需要实现编码器或代码项目解决方案?IIS 不应该负责压缩吗?

那么我还需要做什么才能让它发挥作用?

乔尼

我认为 WCF 绑定可能值得发布,但我不确定它们是否相关(这些来自客户端):

<绑定><wsHttpBinding><绑定名称="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="假"><readerQuotas maxDepth="32" maxStringContentLength="5000000"maxArrayLength="5000000" maxBytesPerRead="5000000" maxNameTableCharCount="5000000"/><reliableSessionordered="true" inactivityTimeout="00:10:00"启用=假"/><安全模式="无"><传输clientCredentialType="None" proxyCredentialType="None" realm=""/><消息clientCredentialType="None"协商服务Credential="false"algorithmSuite="默认"建立安全上下文="假"/></安全><客户><端点地址="http://[省略]/TestMtomService/TextService.svc"binding="wsHttpBinding" bindingConfiguration="WsTextBinding" behaviorConfiguration="GzipCompressionBehavior"contract="TestMtomModel.ICustomerService" name="WsTextEndpoint"></端点></客户><行为><端点行为><行为名称="GzipCompressionBehavior"><gzip压缩/></行为></endpointBehaviors></行为><扩展><行为扩展><添加名称=gzip压缩"type="TestMtomModel.Behavior.GzipCompressionBehaviorExtensionElement, TestMtomModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/></behaviorExtensions></扩展></绑定></wsHttpBinding></绑定>

编辑 2:好吧,对于处于这种神秘情况的其他人,我有一个部分解决方案.即,我已经让 IIS7 至少压缩了来自服务的肥皂消息(尽管我现在在客户端上遇到了一个异常,但是已经发布了几个解决方案).问题是我的服务器上没有安装 DynamicCompressionModule.实际上,对我来说,安装"它意味着只需将这一行添加到 applicationHost.config 的部分:

(假设 dll 存在于该目录中,在我的情况下它确实存在.)然后通过 IIS7 的 Modules 部分为网站或服务器添加模块.

解决方案

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

Everyone, as far as I'm concerned the question is ansered in EDIT 2. Although it's only a partial solution to the IIS side of the problem, it's what I was looking for.


So I'm going to add my query to the small ocean of questions on the subject.

I'm trying to enable GZip compression on large soap responses from a WCF service. So far, I've followed instructions here and in a variety of other places to enable dynamic compression on IIS. Here's my dynamicTypes section from the applicationHost.config:

<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>

And also:

<urlCompression doDynamicCompression="true" doStaticCompression="true" />

Though I'm not so clear on why that's needed.

Threw some extra mime-types in there just in case. I've implemented IClientMessageInspector to add Accept-Encoding: gzip, deflate to my client's HttpRequests. Here's an example of a request-header taken from 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

Now, this doesn't work. There's simply no compression happening, no matter what the size of the message (tried up to 1.5Mb). I've looked at this post, but have not run into an exception as he describes, so I haven't tried the CodeProject implementation that he proposes. Also I've seen a lot of other implementations that are supposed to get this to work, but cannot make sense of them (e.g., msdn's GZip encoder). Why would I need to implement the encoder, or the code-project solution? Shouldn't IIS take care of the compression?

So what else do I need to do to get this to work?

Joni

EDIT: I thought the WCF bindings might be worth posting, though I'm not sure if they're relevant (these are from client):

<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>

EDIT 2: Well for anyone else in this mysterious situation, I have a partial solution. I.e., I've gotten IIS7 to at least compress the soap messages from the service (though I now get an exception on the client, but for that there have been several solutions posted). The problem was that the DynamicCompressionModule was not installed on my server. "Installing" it actually, for me, meant simply adding this line to applicationHost.config's section:

<add name="DynamicCompressionModule" image="%windir%System32inetsrvcompdyn.dll" />

(Assuming the dll exists in that directory, which in my case it did.) And then adding the module via IIS7's Modules section for the website or server.

解决方案

Try adding 'application/soap+xml; charset=utf-8' as dynamic type in applicationHost. Adding this charset part helped me to enable compression for some JSON responses from my http handler.

这篇关于使用 IIS7 上托管的 WCF 进行 GZip 压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆