Skip to main content

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.

Further Reading

GetEndpoints — List all endpoints for a specific server​

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))}");
}

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.

Tokens and Policies

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();