Add optional gzip compression to selfhosted WCF service
===

How can I add a optional gzip compression for my selfhosted WCF service? I'm using for this senario the `WebHttpBinding`. I want to check if the `Accept` header contains the string `gzip` and compress than the content.

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.

In my encoder switch attribute I implemented the `IDispatchMessageFormatter` interface to change on demand the `XmlObjectSerializer`. But I don't unterstand how the output is generated to modify it.

It would be nice if somebody could point my to a possible solution.