title: Add optional gzip compression to selfhosted WCF service
body: <p>How can I add a optional gzip compression for my selfhosted WCF service? I'm using for this senario the <code>WebHttpBinding</code>. I want to check if the <code>Accept</code> header contains the string <code>gzip</code> and compress than the content.</p>
  
  <p>I would like to use a custom Attribute. So far I curriently use a custom Attribute allows me to switch between XML and JSON output, but I have just now no idea how to compress the output.</p>
  
  <p>In my encoder switch attribute I implemented the <code>IDispatchMessageFormatter</code> interface to change on demand the <code>XmlObjectSerializer</code>. But I don't unterstand how the output is generated to modify it.</p>
  
  <p>It would be nice if somebody could point my to a possible solution.</p>