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的。 –