Long time ago I have described how to inject the message header in WCF message by using of Operation Context. After some time I also have posted how to do the same thing in Silverlight.
Now in the time of AppFabric and Access Control Service there is a new requirement caused by REST design of some ACS endpoints. In such cases (REST) services do not relay on SOAP. Because of this appending of header can only make a sense it it is added to HTTP header list.
It is interesting that there are also some cases when you have a SOAP service, but wants to append the header to HTTP. This makes a sense when you work HTTP hosted service
Following example shows how to do this:
/// <summary> /// This method shows how to append the header to HTTP request. /// </summary> private static string InvokeOperation() { MyServiceClient proxy = new MyServiceClient(); using (var factory = new WebChannelFactory<IMyService>()) { using (new OperationContextScope((IClientChannel)proxy.InnerChannel)) { WebOperationContext.Current.OutgoingRequest.Headers.Add("MYHEADER", “BLABLA); return proxy.DoWork(“hello”); } } } |
And this is the message, as you see, with regular SOAP message.
Posted
Jun 04 2011, 12:25 AM
by
Damir Dobric