This project is read-only.

Does WebAPI consider WebOperationContext / OutgoingMessageProperties?

Topics: Web Api
Jan 10, 2012 at 7:45 PM

I have a custom operation invoker (something along the lines of the TaskDispatcher sample), where I'm eventually trying to set the status code and headers of the outgoing response. I tried the following:


1) Created HttpResponseMessageProperty on OperationContext's outgoing message properties and set status code on that

2) Tried setting  WebOperationContext.Current.OutgoingResponse.StatusCode

Neither of the options above had the desired effect. Is WebAPI ignoring WebOperationContext/ outgoing message properties? If so, is there any way at all to manipulate outgoing status code/headers from an operation invoker? I know there are probably other WebAPI hooks where I could do this in an easier fashion, but for my specific purpose, I need to do it in the invoker (unless there is absolutely no way of doing so).


Would appreciate any inputs on this.



Jan 10, 2012 at 8:17 PM

Why do you need a custom OperationInvoker?

You should not use WebOperationContext with Web API. Instead you simply return HttpResponseMessage<T> from your operation to manipulate the headers and status code directly.

Daniel Roth

Jan 10, 2012 at 8:44 PM

Hi Daniel,

It's a little method returns Response<T> and my invoker needs to extract T and return that (just like TaskDispatcher) However, I'd like my custom invoker to be generic and support WebAPI as well as WCF Http etc. My operation can't return there some other way I can get my hands on the HttpResponseMessage? I saw this thread (  that seemed to suggest it was doable, but couldn't make it work.


Thanks so much for your time!


Jan 11, 2012 at 7:20 PM

Closing this thread ...managed to make things work, albeit without being able to communicate values between my custom invoker and Web API components.

Here's the thread with my solution :