I have a WCF service with "ImersonationOption.Required". When using parallelism, impersonation does not seem to leak. For instance:
Parallel.ForEach(items => results.Add(SystemUtil.WindowsUser.Name)
Will return a number with an impersonated user and a number with an application pool user. Can I get myself to work with parallelism?
Best
Mark
Update:
This is the actual code on the IIS side.
[OperationBehavior(Impersonation = ImpersonationOption.Required)] public string[] WhoAmI(int numOfTests) { var tests = new List<int>(); for (var i = 0; i < numOfTests; i++) tests.Add(i); var results = new ConcurrentBag<string>(); Parallel.ForEach(tests, (test) => results.Add(WindowsIdentity.GetCurrent(false).Name)); return results.ToArray(); }
If I pass at numOfTests = 10, it spawns 10 tasks and returns the WindowsIndentity name of each task. What I get is ~ 70% "IIS APPPOOL.NET v4.0" and ~ 30% me.
How can I set it in such a way that my personality always turns it into Parallel.ForEach?
Thanks!
source share