WCF Security Guidance Package Question

Topics: Service Factory Modeling Edition Forum
Mar 19, 2009 at 2:29 PM
I have secured my Service using WCF Security Guidance Package - "Direct Authentication with Windows Accounts ".
In my client code I set the credentials with the following code:

//Direct Authentication pattern 
Proxy.ManagementServiceContractClient oService = new Proxy.ManagementServiceContractClient();
oService.ClientCredentials.UserName.UserName = "UserName:;
oService.ClientCredentials.UserName.Password = "password$";

Now on the Services side I want toa access the UserName that was autheticated.
In my Service code I was reading the Username as:

string UserName = System.Threading.Thread.CurrentPrincipal.Identity.Name;

Is this the proper/best way to get the UserName on the Service side when using Security Guidance Package?
Should I be looking somewhere else to get the UserName?

 

Developer
Mar 19, 2009 at 3:22 PM
You may use:  OperationContext.Current.ServiceSecurityContext.PrimaryIdentity
That way you will get the Identity of the impersonated caller or the current thread identity.