Discovery
Not sure which endpoints are available on the server? Not sure which ones are on the local area network OPC UA Server? Use the Discovery service to find them.
- Basics — Service Sets — Discovery Service Set
- Enable Encryption — Select after obtaining the endpoint SecurityMode
- Required Environment — Test Server Selection
GetEndpoints — List all endpoints for a specific server
- C#
- Python
var endpoints = OpcUaDiscovery.GetEndpoints("opc.tcp://server:4840");
foreach (var ep in endpoints)
{
Console.WriteLine($"URL: {ep.EndpointUrl}");
Console.WriteLine($" SecurityMode: {ep.SecurityMode}");
Console.WriteLine($" SecurityPolicy: {ep.SecurityPolicyUri}");
Console.WriteLine($" UserTokens: {string.Join(",", ep.UserTokens.Select(t => t.TokenType))}");
}
from darra_opcua import OpcUaDiscovery
endpoints = OpcUaDiscovery.get_endpoints("opc.tcp://server:4840")
for ep in endpoints:
print(f"URL: {ep.endpoint_url}")
print(f" SecurityMode: {ep.security_mode}")
print(f" Policy: {ep.security_policy_uri}")
print(f" UserTokens: {ep.user_tokens}")
The returned EndpointDescription list typically contains:
- The three SignAndEncrypt combinations of URL None, Sign, and the same
- UserTokenType published by the server (Anonymous / Username / Certificate / Issued)
Choose one that meets your needs and use it to build EndpointUrl + SecurityMode + SecurityPolicyUri DarraOpcUa.
Of the 4 UserTokenType types published by the server, this current SDK connection path supports only the "Anonymous" and "Username" types. Security policies are automatically selected based on the security mode and implement only #None and #Basic256Sha256.
FindServers — LDS List all servers in the domain
var servers = OpcUaDiscovery.FindServers("opc.tcp://lds-host:4840");
foreach (var s in servers)
{
Console.WriteLine($"App: {s.ApplicationName}");
Console.WriteLine($" AppUri: {s.ApplicationUri}");
Console.WriteLine($" ProductUri: {s.ProductUri}");
foreach (var url in s.DiscoveryUrls)
Console.WriteLine($" Discovery: {url}");
}
LDS = Local Discovery Server: Servers on the same subnet can register with it LDS, allowing FindServers all of them to be discovered.
Cancel — Cancel an uncompleted request
Cancel(requestHandle) Cancel uncompleted requests and return the number of canceled requests. requestHandle The caller must track this information themselves; there is currently SDK no way to retrieve the request handle, so this approach is only available in scenarios where the caller keeps track of the handle themselves.
Common Uses
// 1. Unencrypted quick probe — Decide after obtaining server information
var endpoints = OpcUaDiscovery.GetEndpoints("opc.tcp://server:4840");
var ep = endpoints.First(e => e.SecurityMode == MessageSecurityMode.SignAndEncrypt);
// 2. Use the selected endpoint to establish an actual connection
using var ua = new DarraOpcUa(
endpointUrl: ep.EndpointUrl,
securityMode: ep.SecurityMode,
securityPolicyUri: ep.SecurityPolicyUri,
clientCertificatePfxPath: "client.pfx",
clientCertificatePassword: "123456",
serverCertificatePath: null,
username: null, password: null);
ua.Connect();