我在 WCF 服务和模拟方面遇到了一些问题,我将其提炼为下面的一个简单方法。 WCF 服务当前在 exe 中自行托管。异常消息是“未提供所需的模拟级别,或者提供的模拟级别无效”。检查何时抛出错误,身份模拟级别设置为委派,如我的客户端上指定的那样,并通过 Kerberos 进行身份验证。
我有点困惑,因为在我看来,ImpersonationLevel 和 Authenticaiton 的要求已经得到满足。我的想法是,问题可能与域设置有关,我已经设置并认为设置正确。所以我有两个问题:
- 下面的操作应该成功吗? (或者它有缺陷吗?)
- 需要在 Win2k8 域上配置哪些设置才能使其正常工作?我正在使用两个盒子,它们是同一个 Win2k8 域的成员(它是一个新域,非常普通,目的是测试模拟)。
代码如下:
[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()
测试.bat 文件内容
echo %用户名%
只要您使用 .NET Process 类,它就会存在缺陷,它总是以父进程的身份开始。要以另一个身份运行它,看起来您必须使用 win32 api CreateProcessAsUser (我还没有工作)。
我需要提升运行它(即 Visual Studio 作为管理员)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)