跳到主要内容

Discovery 发现

Discovery 是静态类, 不需要 Session 即可调用. 用于"连接前先探测":

子页跳转
  • 列出某 Server 全部 Endpoint 请参考 GetEndpoints.
  • 通过 LDS 列出域内全部 Server 请参考 FindServers.

用法模式

using DarraOpcUa_Client;

// 1. 先 GetEndpoints 看服务端支持哪些组合
var endpoints = Discovery.GetEndpoints("opc.tcp://server:4840");

// 2. 挑一个匹配的 (例如 SignAndEncrypt + Username)
var ep = endpoints.First(e =>
e.SecurityMode == MessageSecurityMode.SignAndEncrypt &&
e.UserIdentityTokens.Any(t => t.TokenType == UserTokenType.Username));

// 3. 用挑出来的 Endpoint 真正连接
using var ua = new DarraOpcUa(
endpointUrl: ep.EndpointUrl,
securityMode: ep.SecurityMode,
securityPolicyUri: ep.SecurityPolicyUri,
username: "operator", password: "secret",
clientCertPath: "client.pfx", clientKeyPath: "123456");
ua.Connect();

下一步