titanium-as / TitaniumAS.Opc.Client

Open source .NET client library for OPC DA
MIT License
193 stars 94 forks source link

Erorr when trying to connect to OPC DA SERVER on a different machine other than localhost #59

Open sriki24 opened 2 years ago

sriki24 commented 2 years ago

I have a requirement where i need to connect to OPC DA server locally as well to some remote servers in a different PC. The localhost is working fine where as if i provide the IP address of the machine where OPC DA server is running getting the exception CoCreateInstanceEx: The RPC server is unavailable. at TitaniumAS.Opc.Client.Interop.System.Com.CreateInstance(Guid clsid, String host, NetworkCredential credential) at TitaniumAS.Opc.Client.Common.OpcServerEnumeratorAuto.CLSIDFromProgId(String progId, String host) at TitaniumAS.Opc.Client.Da.OpcDaServer.<>cDisplayClass7.b4(String host, String progId) at TitaniumAS.Opc.Client.Common.UrlParser.Parse[T](Uri opcServerUrl, Func3 withProgId, Func3 withCLSID) at TitaniumAS.Opc.Client.Da.OpcDaServer.Connect() at TestHostOPCServerConnection.Program.Main(String[] args) in

Below is the small code created to test connection with OPC DA server

    [MTAThread]
    static void Main(string[] args)
    {

        try
        {
            Bootstrap.Initialize();

            string opcServerName = "XYZ_OpcDaServer.3";               
            string hostName = "10.140.1.2";
            Uri url = UrlBuilder.Build(opcServerName, hostName);
            OpcDaServer server = new OpcDaServer(url);

            server.Connect();  ----> //exception  thrown when try to connect
            if(server.IsConnected)
            {
                //dosomething
            }
        }

}

Note: There is no problem if i give localhost where in if i give IP address of some machine where OPC DA server is running,problem getting connection.

dmitrybond173 commented 2 years ago

In my case it works fine. But need to follow special setup guide. For example for Kepware guide is here - https://www.kepware.com/getattachment/04042e47-c690-467c-a931-a1ca126575db/Remote-OPC-DA-Quick-Start-Guide-DCOM.pdf

So, this problem is not about TitaniumAS.Opc.Client component but about correct DCOM access configuration for the OPC server which are you using.

duduyoyo commented 1 month ago

This is a typical firewall issue in remoter server. If client callback is involved there could be a DCOM configuration issue in client as well.

You can try this one, which intelligently circumvents these kinds of issues by design. Good luck!