本文介绍了如何为WCF服务启用IIS压缩?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前为我的WCF服务使用自定义gzip编码器。我想替换它与内置的IIS 7压缩,如果这是可能的。我不能在网上找到如何做的信息。



有没有办法启用IIS 7压缩WCF服务?
你知道这是否将支持开箱即用的.Net 4?



编辑6月15日: / strong>我仍然在寻找一种方法来替换我们的自定义gzip编码器与主流方法,所以如果你知道如何做的.Net 4和IIS 7,请回答这个问题。



感谢






侧边栏: / strong>



由于我无法通过简单地转动几个旋钮来找到它,所以我决定尝试手动启用它。



到目前为止我有:




  • 安装并启用IIS 7动态压缩模块

  • 更改了applicationHost.config文件的部分以启用 mimeType =application / soap + xml mimeType =应用程序/ xop + xml



我使用HTTP嗅探器Windows窗体)。我看到请求没有 Accept-Encoding:gzip,deflate http标头。



所以我




  • 使用 OperationContextScope 类及其 OutgoingMessageProperties 。 (我将在稍后发布详细信息,如果我找到解决方案)。



使用http sniffer,我可以看到,具有正确的标题:

  POST / ###到我的服务的路径#### / MyService.svc HTTP / 1.1 
MIME-Version:1.0
Content-Type:multipart / related; type =application / xop + xml;
start =< http://tempuri.org/0>;
boundary =uuid:####### some uuid #############;
start-info =application / soap + xml
Accept-Encoding:gzip,deflate
主机:#######我的服务器名称######## #####
Content-Length:1753
Expect:100-continue

但是服务器响应仍然没有压缩。



为什么服务器响应未压缩?我使用正确的MIME类型?一旦我得到服务器返回一个压缩的答案,客户端会自动解压缩,还是必须在客户端写代码解压缩?






感谢您的帮助

解决方案

.aspx页面被压缩,但WCF内容不是。它与WCF服务返回的内容类型有关,后者附加到mime类型。



我使用它在ApplicationHost的下一部分.config:

 < dynamicTypes> 
< add mimeType =text / *enabled =true/>
< add mimeType =message / *enabled =true/>
< add mimeType =application / *enabled =true/>
< add mimeType =* / *enabled =false/>
< / dynamicTypes>

这是我做的(大部分与上面提到的步骤相同):




  • 为IIS角色安装动态压缩角色服务

  • 为用于托管WCF的网站启用动态内容压缩服务

  • 打开%SystemRoot%\system32\inetsrv\config\applicationhost.config并将相关内容类型添加到
  • 部分它仍然没有工作。

  • 我使用Firefox的篡改数据检查了数据,发现返回的内容类型实际上是application / xml; charset = utf-8。

  • 在将完整内容类型(包括; charset = utf-8)添加到此部分后,它的工作原理如下:





 < add mimeType =application / xml; charset = utf-8enabled =true/> 

因为我觉得字符集编码不应该决定压缩是否有效,让IIS压缩所有应用程序/ *内容类型。


I currently use a custom gzip encoder for my WCF service. I want to replace it with the built-in IIS 7 compression if that is possible. I can't find info online on how to that.

Is there any way to enable IIS 7 compression for WCF services?Do you know if this will be supported out-of-the-box with .Net 4?

Edit June 15th: I'm still looking for a way to replace our custom gzip encoder with a mainstream approach so if you know how to do that with .Net 4 and IIS 7, please answer this question.

Thanks


Sidebar : My attempt at doing this manually

Since I can't find how to do it by simply turning a few knobs I decided to try and enable it manually.

So far I have:

  • Installed and enabled the IIS 7 Dynamic Compression Module
  • Changed the section of the applicationHost.config file to enable compression for mimeType="application/soap+xml" and mimeType="application/xop+xml".

I used an HTTP sniffer to sniff traffic sent from my app (Windows Forms). I see that requests do not have the Accept-Encoding:gzip,deflate http header.

So I

  • Added it manually to all outgoing calls using the OperationContextScope class and its OutgoingMessageProperties. (I will post the details later if I find the solution).

With the http sniffer, I can see that the client header now has the correct header:

POST /### path to my service ####/MyService.svc HTTP/1.1
MIME-Version: 1.0
Content-Type: multipart/related; type="application/xop+xml";
    start="<http://tempuri.org/0>";
    boundary="uuid:####### some uuid #############";
    start-info="application/soap+xml"
Accept-Encoding: gzip,deflate
Host: ####### my server name #############
Content-Length: 1753
Expect: 100-continue

But the server response is still not compressed.

Why is the server response not compressed? Have I used the correct mime types? Once I get the server to return a compressed answer, will the client automatically decompress it or will have to write code on the client side to decompress?


Thanks for your help

解决方案

I had the same problem; .aspx pages were compressed but WCF content wasn't. It has to do with the content type returned by the WCF service, which got appended to the mime-type.

I got it to work with the following section in the ApplicationHost.config:

<dynamicTypes>
    <add mimeType="text/*" enabled="true" />
    <add mimeType="message/*" enabled="true" />
    <add mimeType="application/*" enabled="true" />
    <add mimeType="*/*" enabled="false" />
</dynamicTypes>

Here's what I did (most of the same steps as mentioned already):

  • Install the Dynamic Compression Role Service for IIS role
  • Enable Dynamic Content Compression for the website that you use to host the WCF service
  • Open %SystemRoot%\system32\inetsrv\config\applicationhost.config and add the relevant content type to the section of the
  • After this it still didn't work.
  • I checked the data with Firefox' Tamper Data and noticed the content type returned was actually "application/xml; charset=utf-8".
  • After adding the complete content type, including the "; charset=utf-8" to the section, it worked:

<add mimeType="application/xml; charset=utf-8" enabled="true" />

As I felt that the character set encoding should not be determining if the compression works or not, I ended up letting IIS compress all application/* content types.

这篇关于如何为WCF服务启用IIS压缩?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-20 20:03