7
我遇到了一些WCF服务和模拟问题,我将它提炼成了一个简单的方法。 WCF服务目前是在exe中自行托管的。例外消息是“未提供所需的模拟级别,或提供的模拟级别无效”。检查何时抛出错误,Identity ImpersonationLevel设置为委派,如我的客户端上指定的,并通过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()
TEST.BAT文件内容
回声%的用户名%
使用调试器什么'身份'等于之前它进入'使用'块? –
嗨@Rahmhound,这是客户端的登录 - 那是你期望的对吗? –
委派在NT域中被默认禁用。如果需要(看起来像),那么你必须启用它。请参阅[启用约束委派](http://technet.microsoft.com/en-us/library/cc756940(v = ws.10).aspx)或[如何在.NET中使用约束委派启用多跳模拟以及Active Directory](http://www.codeproject.com/Articles/38979/How-to-enable-multi-hop-impersonation-using-constr) –