views:

420

answers:

2

Hi folks,

Does anyone know how to get access to request HTTP headers within MessageEncoder.ReadMessage method? It seems that WCF already "knows" request headers at the point of invoking ReadMessage method, at least Content-Type and Content-Length but I cannot get the access to the Content-Encoding header.

Basically, I'm trying to utilize gzip de/compression for WCF service (http://msdn.microsoft.com/en-us/library/ms751458.aspx) and would like to check if decompression is necessary for incoming request. To do that I'd like to check Content-Encoding header but cannot figure out where to get it. Any ideas?

Thanks!

A: 

Have a look here:

http://frenk.wordpress.com/2009/12/04/gzip-compression-wcfsilverlight/

You'll probably have to code some of it yourself to get access.

Tony
Unfortunately, within the ReadMessage method Message object has not been created yet, so OperationContext.Current and WebOperationContext.Current are null. It seems that it can be done if context (HttpListenerContext, HttpListenerRequest) of underlying HttpChannelListener is accessible, but I don't know yet how to access the listener context without reimplementing it.
AC
A: 

Here's an answer I gave in another thread which explains how you would need to manipulate the headers via the WebOperationContext in another IOperationBehavior which is coupled with the MessageEncoder.

Drew Marsh
Thank you for your response. I understand how WebOperationContext and IOperationBehavior could help to setup Content-Encoding header for _outcoming_ message, but I can't figure out how any service, endpoint or operation-wide behaviors could help to access to the _incoming_ message headers.
AC