I have a WCF service that needs to know the Principal of the caller.
In the service constructor, I:
Principal = OperationContext.Current.IncomingMessageHeaders.GetHeader<MyPrincipal>("myPrincipal", "ns");
and in the calling code there is something like:
using (var factory = new ChannelFactory<IMyService>(localBinding, endpoint))
{
var proxy = factory.CreateChannel();
using (var scope = new OperationContextScope((IContextChannel)proxy))
{
var customHeader = MessageHeader.CreateHeader("myPrincipal", "ns", Thread.CurrentPrincipal);
OperationContext.Current.OutgoingMessageHeaders.Add(customHeader);
newList = proxy.CreateList();
}
}
All of this works great.
My question is: how can I avoid wrapping all proxy method calls in using (var scope...{ [create header and add to OperationContext]?
Can I create my own ChannelFactory that will handle adding the myPrincipal header to the operation context? Something like this will save the entire copy / paste load, which I would rather not do, but I'm not sure how to achieve it :)
thank
source
share