Almost two years ago I have posted in "
Hacking of WCF's OperationContext" about manipulating of header of the message in WCF. The same feature is also provided in Silverlight since RTW 2 BETA2. Here is an example:
Service proxy = new Service(); proxy.OnOperationCompleted += new EventHandler<DoWorkCompletedEventArgs>(onCompleted); using (OperationContextScope ctx= new OperationContextScope(proxy.InnerChannel)) { OperationContext.Current.OutgoingMessageHeaders.Add (MessageHeader.CreateHeader("SomeHeader", "http://daenet.eu", "..."));
proxy.OperationkAsync("foo"); } |
Next example shows how to obtain the header value:
void onCompleted(IAsyncResult result) { Service proxy = (Service1)result.AsyncState; using (OperationContextScope ocs = new OperationContextScope(((Service1Client)proxy).InnerChannel)) { string res = proxy.EndDoWork(result); string header= OperationContext.Current.IncomingMessageHeaders.GetHeader<string> ("SomeHeader", "http://daenet.eu"); } }
|
Posted
Feb 19 2009, 11:43 PM
by
Damir Dobric