3
我查询WCF服务内通过CSHARP/.NET打印机。当本地调用时(即客户端从本地机器运行)它将返回一组打印机。当被远程调用时,它会调用一个不同的集合。为什么我会在WCF远程与本地运行WMI查询时得到不同的结果?
的WCF服务设置为接受并使用在创建客户端传递的凭据模拟。
主要的区别我通过远程调试注意的是在调用的身份验证类型:
WindowsIdentity.GetCurrent()
这是Kerberos的,当远程调用和Neogotiate时,当地叫。
这里是代码的快速取样:
[OperationBehavior(Impersonation = ImpersonationOption.Required)]
public List<string> GetAvailablePrinters()
{
List<string> retval = new List<string>();
using (ManagementClass printerClass = new ManagementClass("win32_printer"))
{
ManagementObjectCollection printers = printerClass.GetInstances();
foreach (ManagementObject printer in printers)
{
if ((bool)printer["Shared"] == true)
retval.Add((string)printer["Name"]);
}
}
return retval;
}
两个呼叫成功,但是我远程获取正确的名单在当地,并没有什么。
下面是边侧两个:
测试可执行文件在本地服务器上运行:
{System.Security.Principal.WindowsIdentity}
AuthenticationType: "Negotiate"
Groups: {System.Security.Principal.IdentityReferenceCollection}
ImpersonationLevel: Impersonation
IsAnonymous: false
IsAuthenticated: true
IsGuest: false
IsSystem: false
m_authType: null
m_groups: {System.Security.Principal.IdentityReferenceCollection}
m_impersonationLevel: Impersonation
m_isAuthenticated: 1
m_name: null
m_owner: null
m_safeTokenHandle: {Microsoft.Win32.SafeHandles.SafeTokenHandle}
m_user: {xxxxx}
Name: "adomain\\auser"
Owner: {xxxxx}
Token: token number
TokenHandle: {Microsoft.Win32.SafeHandles.SafeTokenHandle}
User: {xxxxxxxx}
相同的可执行文件运行远程
{System.Security.Principal.WindowsIdentity}
AuthenticationType: "Kerberos"
Groups: {System.Security.Principal.IdentityReferenceCollection}
ImpersonationLevel: Impersonation
IsAnonymous: false
IsAuthenticated: true
IsGuest: false
IsSystem: false
m_authType: null
m_groups: {System.Security.Principal.IdentityReferenceCollection}
m_impersonationLevel: Impersonation
m_isAuthenticated: 1
m_name: null
m_owner: null
m_safeTokenHandle: {Microsoft.Win32.SafeHandles.SafeTokenHandle}
m_user: {xxxxx}
Name: "adomain\\auser"
Owner: {differnt owner}
Token: different Token number
TokenHandle: {Microsoft.Win32.SafeHandles.SafeTokenHandle}
User: {xxxxxx}
你验证模拟? –
是的,而远程调试,我从即时窗口称为WindowsIdentity.GetCurrent(),而坐在方法的顶部。这就是为什么我知道它是远程运行时的Kerberos和当本地运行时是Neogotiate的。 –