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

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

问题描述

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




所以我要将我的问题添加到关于这个主题的小问题上。



我正在尝试对来自WCF服务的大型soap响应启用GZip压缩。到目前为止,我已按照此处的说明进行操作在IIS上启用动态压缩的各种其他地方。这是applicationHost.config中的dynamicTypes部分:

 < dynamicTypes> 
< add mimeType =text / *enabled =true/>
< add mimeType =message / *enabled =true/>
< add mimeType =application / x-javascriptenabled =true/>
< add mimeType =application / atom + xmlenabled =true/>
< add mimeType =application / xaml + xmlenabled =true/>
< add mimeType =application / xop + xmlenabled =true/>
< add mimeType =application / soap + xmlenabled =true/>
< add mimeType =* / *enabled =false/>
< / dynamicTypes>

还有:

 < urlCompression doDynamicCompression =truedoStaticCompression =true/> 

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



为了以防万一,在那里抛出了一些额外的mime类型。
我已经实现了IClientMessageInspector来添加Accept-Encoding:gzip,deflate到我的客户端的HttpRequests。以下是从fiddler获取的请求标头的示例:

  POST http:// [ignored] /TestMtomService/TextService.svc HTTP / 1.1 
内容类型:application / soap + xml; charset = utf-8
接受编码:gzip,deflate
主持人:[省略]
内容长度:542
预期:100-continue

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



那么我需要做些什么才能让它工作?



Joni



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

 < system.serviceModel> 
< bindings>
< wsHttpBinding>
< binding name =WsTextBindingcloseTimeout =00:01:00openTimeout =00:01:00
receiveTimeout =00:10:00sendTimeout =00:01: 00\" bypassProxyOnLocal = 假
transactionFlow = 假 hostNameComparisonMode = StrongWildcard
maxBufferPoolSize = 5000000 maxReceivedMessageSize = 5000000
messageEncoding = 文本 textEncoding =UTF-8 useDefaultWebProxy =true
allowCookies =false>
将readerQuotas MAXDEPTH = 32 maxStringContentLength = 5000000
的MaxArrayLength = 5000000 maxBytesPerRead = 5000000 maxNameTableCharCount = 5000000/>
< reliableSession ordered =trueinactivityTimeout =00:10:00
enabled =false/>
< security mode =None>
< transport clientCredentialType =NoneproxyCredentialType =Nonerealm =/>
< message clientCredentialType =NonenegotiateServiceCredential =false
algorithmSuite =DefaultestablishSecurityContext =false/>
< / security>
< client>
将端点地址= HTTP:// [省略] /TestMtomService/TextService.svc
结合= 的wsHttpBinding bindingConfiguration = WsTextBinding behaviorConfiguration = GzipCompressionBehavior
合同= TestMtomModel.ICustomerServicename =WsTextEndpoint>
< / endpoint>
< / client>
< behavior>
< endpointBehaviors>
< behavior name =GzipCompressionBehavior>
< gzipCompression />
< / behavior>
< / endpointBehaviors>
< / behavior>
< extensions>
< behaviorExtensions>
将添加名称= gzipCompression
型= TestMtomModel.Behavior.GzipCompressionBehaviorExtensionElement,TestMtomModel,版本= 1.0.0.0,文化=中性公钥=空/>
< / behaviorExtensions>
< / extensions>
< / binding>
< / wsHttpBinding>
< / bindings>



编辑2:
对于处于这种神秘局面的其他人来说,我有一个局部解决方案。即,我已经让IIS7至少压缩来自服务的soap消息(虽然我现在在客户端上获得了一个例外,但是为此已经发布了几个解决方案)。
问题是我的服务器上没有安装DynamicCompressionModule。对我来说,实际上安装它意味着只需将此行添加到applicationHost.config的部分:

 < add name = DynamicCompressionModuleimage =%windir%\ System32 \inetsrv \ compdyn.dll/> 

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

解决方案

尝试添加'application / soap + xml; charset = utf-8'作为applicationHost中的动态类型。添加这个charset部分帮助我从我的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%\System32\inetsrv\compdyn.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天全站免登陆