2013-02-13 122 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