I have a WCF DataService (v5.2) that overrides OnStartProcessingRequest(ProcessRequestArgs args)
. I want to add some headers to the response (in this method that I assume is the right place?). I first tried this:
args.OperationContext.ResponseHeaders.Add(...)
That didn't work. I then tried this:
OperationContext.Current.OutgoingMessageHeaders.Add(...)
That didn't work. I tried adding a new OperationContextScope on that sucker. It still failed. At last I tried this:
HttpContext.Current.Response.AddHeader(...);
That option worked! (By "work" I mean that it actually showed up in the response to the the client.) Why didn't the first two options work?
After reading further on the web I discovered that
WebOperationContext.Current.OutgoingResponse.Headers.Add(...)
also works. Why on earth do we have four current contexts inside this method? How is a person to know which one to use (at runtime)? Which ones are valid in my [WebGet]
methods? Which ones are valid in my [QueryInterceptor]
methods? Which context is guaranteed to have the right request headers? (I've been using args.OperationContext for that presently.)