2013-02-13 128 views
0

現在,我一直被困在這個問題現在約5天。COM - 訪問被拒絕

基本上我試圖從遠程PC連接到OPC服務器(Kepware)。如果我在安裝了Kepware的服務器上運行它(在本例中爲192.168.102.104),我編寫的代碼就可以工作。

但是,如果我從遠程PC運行它,我得到以下錯誤。

System.UnauthorizedAccesException: Access is denied 
(Error from HRESULT: 0x080070005 E_ACCESSIFDENIED)) 

我已經安裝以下說明服務器: http://www.kepware.com/Support_Center/SupportDocuments/Remote%20OPC%20DA%20-%20Quick%20Start%20Guide%20(DCOM).pdf

的電腦是不是在一個域和兩臺計算機包含具有相同密碼的用戶管理員。

誰能告訴我,如果這個問題可能是與電腦設置或我的代碼

代碼::

class Program 
{ 
    static void Main(string[] args) 
    { 
     try 
     { 
      Unmanaged.CoInitializeSecurity(IntPtr.Zero, -1, IntPtr.Zero, IntPtr.Zero, 
              Unmanaged.RpcAuthnLevel.Connect, 
              Unmanaged.RpcImpLevel.Anonymous, IntPtr.Zero, 
              Unmanaged.EoAuthnCap.None, IntPtr.Zero); 

      using (new Impersonation("Administrator", "TEST", "Password")) 
      { 
       OPCServer opcServer = new OPCServer(); 
       opcServer.Connect("Kepware.KEPServerEx.V5", "192.168.102.104"); 
       Console.WriteLine(opcServer.ServerName); 
      } 
     } 
     catch (Exception ex) 
     { 
      Console.WriteLine("Connection error:::\n\n{0}\n\n",ex); 
      Console.ReadLine(); 
     } 
     Console.ReadLine(); 
    } 
} 

非託管類::

partial class Unmanaged 
{ 
    [DllImport("ole32.dll")] 
    public static extern int CoInitializeSecurity(IntPtr pVoid, int 
     cAuthSvc, IntPtr asAuthSvc, IntPtr pReserved1, RpcAuthnLevel level, 
     RpcImpLevel impers, IntPtr pAuthList, EoAuthnCap dwCapabilities, IntPtr 
     pReserved3); 

    public enum RpcAuthnLevel 
    { 
     Default = 0, 
     None = 1, 
     Connect = 2, 
     Call = 3, 
     Pkt = 4, 
     PktIntegrity = 5, 
     PktPrivacy = 6 
    } 

    public enum RpcImpLevel 
    { 
     Default = 0, 
     Anonymous = 1, 
     Identify = 2, 
     Impersonate = 3, 
     Delegate = 4 
    } 

    public enum EoAuthnCap 
    { 
     None = 0x00, 
     MutualAuth = 0x01, 
     StaticCloaking = 0x20, 
     DynamicCloaking = 0x40, 
     AnyAuthority = 0x80, 
     MakeFullSIC = 0x100, 
     Default = 0x800, 
     SecureRefs = 0x02, 
     AccessControl = 0x04, 
     AppID = 0x08, 
     Dynamic = 0x10, 
     RequireFullSIC = 0x200, 
     AutoImpersonate = 0x400, 
     NoCustomMarshal = 0x2000, 
     DisableAAA = 0x1000 
    } 
} 

的模擬類只是模仿本地用戶管理員。

當我與凱譜華在服務器上運行此我得到的輸出 - Kepware.KepServerEx.V5 當我在客戶端PC上運行它,我得到上述錯誤

任何幫助將不勝感激。謝謝。

+0

您位於電線的錯誤末端。您不能模擬僅由該機器知道的用戶帳戶,用戶名稱匹配無關緊要。你將不得不通過遠程機器上的DCOM配置hoopla。 – 2013-02-13 09:51:32

回答

3

發現問題的根源。

爲什麼總是這樣,我一發布就知道了?

問題出在服務器的設置上。我不會在這裏詳細介紹所有的細節,但是它將DCOM設置中的身份(在DCONcnfg中)設置爲錯誤的用戶。

顯然我忽略了服務器設置說明的那一點。

對不起,浪費任何人的時間。

+3

http://www.codinghorror.com/blog/2012/03/rubber-duck-problem-solving.html – 2013-02-13 09:46:30