I am trying to extract the login name from a web service that was authenticated using a custom username validator. It validates ok, but I am unable to extract this info within the service implementation.
So far, I have tried the following:
- return WebOperationContext.Current.IncomingRequest.Headers[HttpRequestHeader.Authorization];
- return OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.Name;
- return ServiceSecurityContext.Current.WindowsIdentity.Name;
- return Thread.CurrentPrincipal.Identity.Name;
The first works fine if the service is using REST, but returns an empty string with SOAP, so I am thinking the authorization credentials are in the SOAP body rather than the HTTP header in that instance. (The WCF service supports both REST and SOAP,
so I will need a solution that will work with either).
The latter three attempts throw a null reference exception.
View Complete Post