I am using WCF service on VS2010.
On my client side, Thread.CurrentPrincipal is populated with Customized Principal object which implements IPrincipal.
But when the WCF service method gets invoked, the Thread.CurrentPrinicpal on the service side is
WindowsPrincipal which is the default.
How can I make the service side Thread.CurrentPrincipal same as the client side (Customized Principal object)?
Please help.
Thanks
Here’s one way, I don’t know if there’s a more easy way though:
You need an IEndpointBehaviour implementation that in the ApplyClientBehavior method attaches a custom message inspector which in turn adds a custom message header (in the BeforeSendRequest method) containing your custom principal instance. You might need to decorate your custom principal object with Data Contract attribute in order for it to serialize. Then, implement a custom authorization policy (similar to http://burcakcakiroglu.com/?p=2189) which will run at the server end and in the Evaluate method read the custom message header back out again and copy the principal in the header into evaluationContext.Properties[“Principal”].