본문으로 건너뛰기

생성자

DarraOpcUa 두 가지 오버로드가 제공됩니다: 간소화된 생성자(일반적인 매개변수 + 기본값 추론)와 전체 구성 생성자(모든 필드를 명시적으로 전달).

사전 읽기
  • 암호화 매개변수 (SecurityMode / SecurityPolicyUri / 인증서)는 다음을 참조하십시오. 보안 암호화.
  • 서버 측 사전 스캔은 다음을 참조하십시오. Discovery.
  • 연결 후의 조작 방법은 다음을 참조하십시오. 연결 관리.

구조 간소화 (권장)​

public DarraOpcUa(
string endpointUrl,
MessageSecurityMode securityMode = MessageSecurityMode.None,
string username = null,
string password = null,
uint sessionTimeoutMs = 60_000,
uint requestTimeoutMs = 10_000,
uint connectTimeoutMs = 10_000,
string clientCertPath = null,
string clientKeyPath = null,
string serverCertPath = null,
string securityPolicyUri = null);

매개변수​

분류속성유형접근설명
필수endpointUrlstringinOPC UA 엔드포인트, 형식: opc.tcp://host:port
보안securityModeMessageSecurityModeinNone / Sign / SignAndEncrypt, 기본값: None
securityPolicyUristringin지정하지 않으면 mode에 따라 자동으로 선택됨 (None → #None, 그 외 → #Basic256Sha256)
clientCertPathstringin클라이언트 PFX 경로 (Sign / SignAndEncrypt 필수, 누락 시 Connect가 즉시 실패함)
clientKeyPathstringin⚠ **개인 키 경로가 아닙니다** — 바로 그 PFX 의**비밀번호**. 이름에 Key가 포함되어 있지만, 전달되는 것은 비밀번호 문자열(예: "123456")이며, 파일 경로를 전달하면 PFX를 풀 수 없습니다
serverCertPathstringin서버 인증서 **PFX** 파일 경로 (PKCS#12, 반드시 비밀번호가 없어야 함 — 아래 「서버 인증서 검증」 참조). ⚠ 전달하지 않으면 **TOFU가 아닙니다**
로그인usernamestringinnull = 익명, 비어 있지 않음 = UsernameIdentityToken
passwordstringinusername과 함께 사용; 전달하지 않으면 빈 문자열로 처리
타임아웃sessionTimeoutMsuintin서버 측 세션 타임아웃, 기본값 60 000 ms (60초)
requestTimeoutMsuintin단일 RPC 타임아웃, 기본값 10 000 ms (10초)
connectTimeoutMsuintin연결 시간 초과, 기본값 10 000 ms (10초)

예시​

// 1. 익명 + 평문 (개발 단계)
using var ua = new DarraOpcUa("opc.tcp://localhost:4840");

// 2. 익명 + Sign 암호화 (서버 인증서 고정)
using var ua2 = new DarraOpcUa("opc.tcp://server:4840",
securityMode: MessageSecurityMode.Sign,
clientCertPath: @"C:\certs\client.pfx",
clientKeyPath: "123456", // PFX 비밀번호
serverCertPath: @"C:\certs\server.pfx");

// 3. 사용자 이름 + SignAndEncrypt (일반적인 생산)
using var ua3 = new DarraOpcUa("opc.tcp://server:4840",
securityMode: MessageSecurityMode.SignAndEncrypt,
username: "operator",
password: "secret",
clientCertPath: @"C:\certs\client.pfx",
clientKeyPath: "123456",
serverCertPath: @"C:\certs\server.pfx");

서버 인증서 검증 (필독)​

serverCertPath를 전달하지 않을 때는 TOFU / 지문 고정이 전혀 없습니다. SDK의 실제 행동은 두 가지로 나뉩니다:

구성실제 행동서버 측 신원이 인증되었는지 여부
securityMode != None이고 serverCertPath를 전달한 경우귀하가 제공한 인증서 파일을 직접 불러와, 이를 사용하여 암호화 채널을 개설합니다.네 — 채널은 귀하가 등록한 인증서를 기반으로 생성됩니다.
securityMode != None이고 serverCertPath를 전달하지 않은 경우먼저 None 평문 채널로 GetEndpoints를 호출해 서버가 자체 보고한 인증서를 가져온 다음, 이를 사용하여 암호화 채널을 개설합니다.아니요 — 인증서가 아직 인증되지 않은 동일한 평문 링크에서 발급된 것으로, 중간자가 이를 대체할 수 있음
securityMode == None전체 과정이 평문으로 전송됨아니요

즉: serverCertPath를 전달하지 않으면 서버 신원을 검증하지 않는 것과 같습니다. "처음 사용할 때 기억한다"는 방식이 아닙니다. SDK는 "첫 인증서 저장 + 이후 지문 대조" 기능을 제공하지 않습니다.

그 밖의 몇 가지 함정:

  1. 전송되었으나 로딩에 실패하면 자동으로 하위 버전으로 전환됩니다. — 인증서 로딩에 실패하면 WARN 메시지가 한 번만 표시되고, 위 표에 나와 있는 평문 경로로 되돌아가지만 연결은 여전히 성공합니다. 인증서가 실제로 적용되었는지 확인하려면, 연결 후 직접 다시 한 번 확인해 보십시오.
  2. serverCertPath는 PFX (PKCS#12)만 인식합니다 — 누드 DER / PEM 파일은 불러올 수 없습니다. OpcUaDiscovery.GetEndpoints가 반환하는 EndpointDescription.ServerCertificate 값은 DER 바이트이며, 이를 고정하려면 먼저 직접 PFX로 포장해야 합니다.
  3. 서버 측 PFX는 반드시 비밀번호가 없어야 합니다 — 비밀번호가 있는 PFX는 로딩에 실패하고, 1번 항목의 무음 다운그레이드 상태로 빠집니다.
  4. securityMode == None 이 경우 두 인증서 매개변수 모두 고려되지 않습니다., 사용자 이름과 비밀번호도 평문으로 전송됩니다.

보안: securityMode 최소 Sign + 전송 serverCertPath (사전에 관리자로부터 받은 비밀번호 없는 PFX).

전체 구성 구조​

public DarraOpcUa(
string endpointUrl,
MessageSecurityMode securityMode,
string securityPolicyUri,
string clientCertificatePfxPath,
string clientCertificatePassword,
string serverCertificatePath,
string username,
string password,
uint sessionTimeoutMs = 60_000,
uint requestTimeoutMs = 10_000,
uint connectTimeoutMs = 10_000);

모든 필드를 명시적으로 전달합니다. 간소화된 생성 방식과의 차이점은 자동 securityPolicyUri 추론에 securityMode 따르지 않는다는 점입니다. —— 빈 문자열을 전달할 때만 해당됩니다 #None. "결과 GetEndpoints 팩토리 기반 생성" 시나리오에 적합합니다:

var endpoints = OpcUaDiscovery.GetEndpoints("opc.tcp://server:4840");
var ep = endpoints.First(e =>
e.SecurityMode == MessageSecurityMode.SignAndEncrypt);

using var ua = new DarraOpcUa(
endpointUrl: ep.EndpointUrl,
securityMode: ep.SecurityMode,
securityPolicyUri: ep.SecurityPolicyUri,
clientCertificatePfxPath: @"C:\certs\client.pfx",
clientCertificatePassword: "123456", // 바로 PFX 암호입니다. 개인 키 파일이 아닙니다.
serverCertificatePath: @"C:\certs\server.pfx", // 서버 인증서를 고정; null을 전달하면 서버 신원을 확인하지 않음
username: "operator",
password: "secret");

예외​

시공 기간 (new DarraOpcUa(...)):

예외이유
ArgumentNullExceptionendpointUrl null / 빈 문자열
OpcUaException세션 생성 실패, StatusCode 구체적인 상태 코드는 다음과 같습니다.

시공 단계인증서 로드 및 검증 안 함 — 인증서 경로는 일단 기록해 두는 것일 뿐이며, 인증서 파일을 실제로 읽는 작업은 연결 시에 이루어집니다.

연결 기간 (ua.Connect())에서야 비로소 인증서 로딩을 시도했으나, 실패하여 다음 예외가 OpcUaException 발생했습니다:

StatusCode이유
BadCertificateInvalid클라이언트 PFX 로딩 실패 (비밀번호 오류 / 파일 손상)
raw 0x80AB0000 (BadInvalidArgument)Sign / SignAndEncrypt 하지만 전달되지 않았다 clientCertPath

자원 관리​

DarraOpcUa 구현 IDisposable.반드시 를 사용하거나 using 명시적으로 Dispose를 호출해야 합니다.:

// 추천: using 자동 Dispose
using var ua = new DarraOpcUa(...);

// 또는 명시적으로
var ua = new DarraOpcUa(...);
try { /* ... */ }
finally { ua.Dispose(); }

Dispose() 이동등(반복 호출이 안전함)입니다. 이 메서드는 세션을 직접 종료하고 모든 리소스를 해제하며, "능동적 연결 해제" Disconnect() Disconnected 이벤트를 다시 발생시키지 않습니다. 해당 이벤트를 수신하려면 먼저 명시적으로 Dispose를 호출한 후 ua.Disconnect() 이 메서드를 호출해야 합니다.

다음 단계​