title: How to enable IIS compression for WCF services?
body: <p>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.</p>
  
  <p>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?</p>
  
  <p><strong><em>Edit June 15th:</strong> 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.</em></p>
  
  <p>Thanks</p>
  
  <hr>
  
  <p><strong>Sidebar : My attempt at doing this manually</strong></p>
  
  <p>Since I can't find how to do it by simply turning a few knobs I decided to try and enable it manually.</p>
  
  <p>So far I have:</p>
  
  <ul>
  <li>Installed and enabled the IIS 7 Dynamic Compression Module</li>
  <li>Changed the  section of the applicationHost.config file to enable compression for <code>mimeType="application/soap+xml"</code> and <code>mimeType="application/xop+xml"</code>.</li>
  </ul>
  
  <p>I used an HTTP sniffer to sniff traffic sent from my app (Windows Forms). I see that requests do not have the <code>Accept-Encoding:gzip,deflate</code> http header. </p>
  
  <p>So I </p>
  
  <ul>
  <li>Added it manually to all outgoing calls using the <code>OperationContextScope</code> class and its <code>OutgoingMessageProperties</code>. (I will post the details later if I find the solution).</li>
  </ul>
  
  <p>With the http sniffer, I can see that the client header now has the correct header:</p>
  
  <pre><code>POST /### path to my service ####/MyService.svc HTTP/1.1
  MIME-Version: 1.0
  Content-Type: multipart/related; type="application/xop+xml";
      start="&lt;http://tempuri.org/0&gt;";
      boundary="uuid:####### some uuid #############";
      start-info="application/soap+xml"
  Accept-Encoding: gzip,deflate
  Host: ####### my server name #############
  Content-Length: 1753
  Expect: 100-continue
  </code></pre>
  
  <p>But the server response is still not compressed. </p>
  
  <p>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?</p>
  
  <hr>
  
  <p>Thanks for your help</p>