I have a WCF DataService (v5.2) that overrides OnStartProcessingRequest(ProcessRequestArgs args) . I want to add some headers to the answer (in this method, which I assume is the right place?). I tried this first:
args.OperationContext.ResponseHeaders.Add(...)
This did not work. Then I tried this:
OperationContext.Current.OutgoingMessageHeaders.Add(...)
This did not work. I tried to add a new OperationContextScope on this suction cup. He still failed. Finally I tried this:
HttpContext.Current.Response.AddHeader(...);
This option worked! (By βworkβ, I mean that he really appeared in the response to the client.) Why didn't the first two options work?
After reading on the Internet, I found that
WebOperationContext.Current.OutgoingResponse.Headers.Add(...)
also works. Why do we have four current contexts inside this method? How can a person know which one to use (at runtime)? Which of them are valid in my [WebGet] methods? Which of them are valid in my [QueryInterceptor] methods? In what context are the correct request headers guaranteed? (I used args.OperationContext for this currently.)
source share