Client Impersonation in WCF
Software Development February 26th, 2008
Recently I got a question about impersonation in WCF. What should we do in order to impersonate the client?
It’s simple:
Client Side
// Create a client with given client endpoint configurationMyServiceClient client = new MyServiceClient();client.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
Server Side
if (ServiceSecurityContext.Current.WindowsIdentity.ImpersonationLevel == TokenImpersonationLevel.Impersonation || ServiceSecurityContext.Current.WindowsIdentity.ImpersonationLevel == TokenImpersonationLevel.Delegation){ // Impersonate. using(ServiceSecurityContext.Current.WindowsIdentity.Impersonate()) { Console.WriteLine("Impersonating the caller"); }}
Similar Posts:
- WCF Impersonation With Client
- Query types using LINQ
- Azure .NET Services – A Twitter Service Bus
- .NET Framework 4 availability on Server Core
- WCF Articles
Tags: WCF
About


This comment originally written by:
Recently I got a question about impersonation in WCF. What should we do in order to impersonate the client? It's simple!
This comment originally written by:JD Stuart
I'm using Silverlight as a client, and I already enabled my web application to use aspNetContext = true.
The ServiceSecurityContext.Current is always null.
How do I impersonate a Active Directory user, in my wcf service, using Silverlight as my client?
This comment originally written by:Maor David-Pur
Hi Marc
You should catch this issue – probably you cannot impersonate your client.
This comment originally written by:Marc S
What if ServiceSecurityContext.Current is null?
This comment originally written by:Maor David-Pur
Mr. Lavian, it’s screen resolution issue.
This is the code:
if (ServiceSecurityContext.Current.WindowsIdentity.ImpersonationLevel == TokenImpersonationLevel.Impersonation || ServiceSecurityContext.Current.WindowsIdentity.ImpersonationLevel == TokenImpersonationLevel.Delegation)
{ // Impersonate.
using (ServiceSecurityContext.Current.WindowsIdentity.Impersonate())
{ Console.WriteLine("Impersonating the caller");
}
}
This comment originally written by:Gilad Lavian
I cant see the code after:
"ImpersonationLevel == TokenImpersonationLevel.Impersonation "
Can you please fix it…