How to identify authenticated user in WCF?

I have a WCF service that will use basic authentication and would like to determine who "who" is trying to use this service. I know that HttpContext.Current is NULL in the WCF service, but does not know that the alternative is to get a username.

For a website, I can use:

userName = HttpContext.Current.Request.ServerVariables["LOGON_USER"];

How do I get a username in a WCF service?

+5
source share
2 answers

Something like this maybe?

string login = OperationContext.Current
                               .ServiceSecurityContext
                               .PrimaryIdentity
                               .Name;

Obviously, this helps to check for null reference exceptions along this path, but you get the idea.

+8
source

OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.Name

+2

All Articles