Tuesday, July 21, 2009

Retrieving Username in WCF server Side in wsHttpBinding




While using custom validation in WCF using "UserNamePasswordValidator" every time we make a call to the service user will be authenticated with the Validate (.....) Method. But after authentication how do we retrive the username . Write the below code to retrive the UserName while you use wsHttpBinding.


OperationContext objOpeContext = OperationContext.Current;
ServiceSecurityContext objSSContext = objOpeContext.ServiceSecurityContext;
string strUserName = objSSContext.PrimaryIdentity.Name;


The strUserName will provide you the userName who is making the call.

More info available @ http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/0c69f2d3-3346-4cad-90f5-87ff34aca9cf/

No comments: