WCF Http channel broken in the current bits

Topics: Web Api
Feb 2, 2011 at 12:38 PM

I am trying to port some of the channel interceptors (REST Starter kit) to the current WCF Http bits, but it looks like the current channel implementation changed considerably.

This line of code used to work with the previous WCF Http Channel,

HttpRequestMessageProperty request = (HttpRequestMessageProperty)requestMessage.Properties[HttpRequestMessageProperty.Name]; 

requestMessage in the code above is an instance of the Message class received in the channel or interceptor. It looks like the channel implementation in the new bits is creating a new message and not setting the properties correctly so there is no way to get the Http Request from the message. The only workaround I found so far is to use reflection against a public method in the new HttpMessage class (which is internal),

Message requestMessage = requestContext.RequestMessage;
HttpRequestMessage request = (HttpRequestMessage)(requestMessage.GetType().InvokeMember("GetHttpRequestMessage",
                BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod, null, requestMessage, null));

Not sure what the plans for a new channel model are, but it would be nice to have support at least for the existing WCF http channels or interceptors.


Feb 2, 2011 at 3:27 PM

Two things Pablo.


1. The new channels that are coming (now renamed to MessageHandler will give you the HTTP messages in the signature of the methods.


2. Second there are extension methods of Message to get to the HTTP messages, see ToHttpRequestMessage and ToHttpResponseMessage.

3. Yes the properties will not work. We made a bunch of deliberate decisions to not use message in a generic waybut as a carrier for the new pure messages.