我在使用WCF服务和模拟时遇到一些问题,下面将其简化为一种简单的方法。 WCF服务当前是自托管在exe中的。异常消息是“未提供所需的模拟级别,或者提供的模拟级别无效”。检查何时引发错误,将Identity ImpersonationLevel设置为委托,这在我的客户端上已指定,并且已通过Kerberos进行了身份验证。
我有点不解,因为在我看来满足了ImpersonationLevel和Authenticaiton的要求。我的想法是问题可能与域设置有关,我已经设置并认为设置正确。所以我有两个问题:
代码如下:
[OperationBehavior(Impersonation = ImpersonationOption.Required)] public string Test() { WindowsIdentity identity = ServiceSecurityContext.Current.WindowsIdentity; using (identity.Impersonate()) { ProcessStartInfo pi = new ProcessStartInfo(@"c:\temp\test.bat"); pi.UseShellExecute = false; pi.RedirectStandardOutput = true; Process p = Process.Start(pi); // exception thrown here! p.WaitForExit(); string o = p.StandardOutput.ReadToEnd(); return o; } }
异常详细信息:
Win32Exception occurred: Either a required impersonation level was not provided, or the provided impersonation level is invalid at System.Diagnostics.Process.CreatePipeWithSecurityAttributes(SafeFileHandle& hReadPipe, SafeFileHandle& hWritePipe, SECURITY_ATTRIBUTES lpPipeAttributes, Int32 nSize) at System.Diagnostics.Process.CreatePipe(SafeFileHandle& parentHandle, SafeFileHandle& childHandle, Boolean parentInputs) at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo) at System.Diagnostics.Process.Start() at System.Diagnostics.Process.Start(ProcessStartInfo startInfo) at MonetEnterprise.Service.SecurityService.Test()
Test.bat文件的内容
echo%username%
我在使用WCF服务和模拟时遇到一些问题,下面将其简化为一种简单的方法。 WCF服务当前是自托管在exe中的。异常消息是“要么...
只要您使用.NET Process类,它就有缺陷,它将始终以父进程的身份开头。要以其他身份运行它,您似乎必须使用win32 api CreateProcessAsUser(我还没有工作)。
这解决了我的应用程序的问题: