Professional Communication
Software Development Tools

logos

Online Forums

Technical support is provided through Support Forums below. Anybody can view them; you need to Register/Login to our site (see links in upper right corner) in order to Post questions. You do not have to be a licensed user of our product.

Please read Rules for forum posts before reporting your issue or asking a question. OPC Labs team is actively monitoring the forums, and replies as soon as possible. Various technical information can also be found in our Knowledge Base. For your convenience, we have also assembled a Frequently Asked Questions page.

Do not use the Contact page for technical issues.

Connecting to a PLC with anonymous users turned off

More
20 Nov 2025 21:34 #14472 by Cwardltu
Is it possible to connect to a plc using a username and password with anonymous users turned off and not trusted cert configured. I am having issues doing so; initially i connect fine but if i were to reinitialize i start getting issues like the ones below:

I have also added a code snipit below.

x80860000: OPC UA service result - {BadSecureChannelClosed}. The secure channel has been closed. [...]
[Connection Event] Server is UNAVAILABLE - OPC UA service result - {BadSecureChannelClosed}. The secure channel has been closed.
+ The server may have rejected the connection because it does not trust the client (e.g. certificate problem); check the diagnostics on the server side, if possible.
+ The client method called (or event/callback invoked) was 'ServerConditionChanged'.

Code:
public void ConnectAsync(string serverURL, string userName = null, string password = null) {     if (string.IsNullOrWhiteSpace(serverURL))         throw new ArgumentNullException(nameof(serverURL));     if (_connected)         Disconnect();     if (_client == null)         _client = new EasyUAClient();     // Accept any certificate     EasyUAClientCore.SharedParameters.EngineParameters.CertificateAcceptancePolicy.AcceptAnyCertificate = true;     _serverUrl = serverURL;     Console.WriteLine("========================================");     Console.WriteLine($"[Connect] Server URL: {serverURL}");     // Simple endpoint creation - let client auto-select best available     Endpoint = new UAEndpointDescriptor(serverURL);     // Add username/password if provided     if (!string.IsNullOrWhiteSpace(userName) && !string.IsNullOrWhiteSpace(password))     {         Console.WriteLine($"[Connect] Username: {userName}");         Endpoint.UserIdentity.UserNameTokenInfo = new OpcLabs.BaseLib.IdentityModel.User.UserNameTokenInfo(userName, password);     }     else     {         Console.WriteLine("[Connect] Authentication: Anonymous");     }     // Try to connect by reading namespaces     _namespaces = new Dictionary<int, string>();     try     {         Console.WriteLine("[Connect] Connecting...");         var nsValues = _client.ReadValue(Endpoint, UAVariableIds.Server_NamespaceArray);         if (nsValues != null && nsValues is string[] namespaceValues)         {             int i = 0;             foreach (var nsValue in namespaceValues)             {                 _namespaces.Add(i++, nsValue);             }             Console.WriteLine($"[Connect] ✓ SUCCESS - {_namespaces.Count} namespaces");         }     }     catch (Exception ex)     {         Console.WriteLine("========================================");         Console.WriteLine("[Connect] ✗ FAILED");         Console.WriteLine($"[Connect] Exception: {ex.GetType().Name}");         Console.WriteLine($"[Connect] Message: {ex.Message}");         if (ex.InnerException != null)         {             Console.WriteLine($"[Connect] Inner: {ex.InnerException.GetType().Name}");             Console.WriteLine($"[Connect] Inner Message: {ex.InnerException.Message}");             if (ex.InnerException.InnerException != null)             {                 Console.WriteLine($"[Connect] Inner-Inner: {ex.InnerException.InnerException.Message}");             }         }         Console.WriteLine("========================================");         throw;     }     _connected = _namespaces.Count > 0;     if (_connected)     {         Console.WriteLine("========================================");     }     // SET UP CONNECTION MONITORING     _connectionMonitoring = _client.GetService<IEasyUAClientConnectionMonitoring>();     if (_connectionMonitoring != null)     {         _connectionMonitoring.ServerConditionChanged += onServerConditionChanged;         Console.WriteLine("Connection monitoring enabled");     }     else     {         Console.WriteLine("Warning: Connection monitoring service not available");     }     _connectionControl = _client.GetService<IEasyUAClientConnectionControl>();     if (_connectionControl == null)     {         Console.WriteLine("Warning: Connection control service not available");     } }

Please Log in or Create an account to join the conversation.

Moderators: supportvaclav.zaloudek
Time to create page: 0.131 seconds