2011-11-01 44 views
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} 
+0

你验证模拟? –

+0

是的,而远程调试,我从即时窗口称为WindowsIdentity.GetCurrent(),而坐在方法的顶部。这就是为什么我知道它是远程运行时的Kerberos和当本地运行时是Neogotiate的。 –

回答

2

看来,打印机,您试图名单是运行WCF Servi大街远程打印机到机器CE。模拟只允许您访问当地资源可用的机器上被调用。这个关于impersonation and delegation in WCF的MSDN文章应该能让你走上正确的道路。您将需要实施委派来列出WCF服务中的远程资源,或者根本不使用委派,并使WCF服务在可以列出远程打印机的域帐户下运行。

相关问题