Мое приложение C# использует стек OPC UA Core в качестве клиента для подключения к ПЛК, работающему в качестве сервера. Я не использую OPC UA SDK, потому что приложение WPF, а SDK непонятен.
Я ознакомился с различными справочными материалами (включая OPC UA SDK и Converter Systems LLC набор инструментов WPF). ) и собрал собственный метод настройки объекта ITransportChannel
для передачи конструктору Opc.UaSessionClient
.
Проблема, с которой я столкнулся, заключается в том, что для получения описания и конфигурации конечной точки, которые соответствуют ожидаемым значениям сервера, я использую ConfiguredEndpoint.UpdateFromServer
, но это выдает ServiceResultException(BadSecureChannelClosed)
, когда его объект DiscoveryClient
закрывается.
Я не вижу, чтобы об этом исключении сообщал проект SimpleOpClient
, включенный в SDK (что никоим образом не просто).
Любые идеи, что может быть не так с этой функцией?
private static ITransportChannel CreateTransportChannel(
ApplicationConfiguration appConfig,
String discoveryUrl)
{
// parse the selected URL.
Uri uri = new Uri(discoveryUrl);
EndpointDescription endpointDescription = new EndpointDescription
{
EndpointUrl = uri.ToString(),
SecurityMode = MessageSecurityMode.None,
SecurityPolicyUri = "http://opcfoundation.org/UA/SecurityPolicy#None"
};
// Configure the endpoint.
ServiceMessageContext messageContext = appConfig.CreateMessageContext();
EndpointConfiguration endpointConfiguration = EndpointConfiguration.Create(appConfig);
ConfiguredEndpoint endpoint = new ConfiguredEndpoint(null, endpointDescription, endpointConfiguration);
// The server may require that the endpoint configuration be adjusted
// to match its own settings.
if (endpoint.UpdateBeforeConnect)
{
// Update endpoint description using the discovery endpoint.
// EXCEPTION thrown during this call.
endpoint.UpdateFromServer(BindingFactory.Create(appConfig, messageContext));
endpointDescription = endpoint.Description;
endpointConfiguration = endpoint.Configuration;
}
// Sanity check for the presence of required security certificates.
X509Certificate2 clientCertificate = null;
if (endpointDescription.SecurityPolicyUri != SecurityPolicies.None)
{
if (appConfig.SecurityConfiguration.ApplicationCertificate == null)
{
Utils.Trace("ApplicationCertificate missing from Configuration.");
throw ServiceResultException.Create(StatusCodes.BadConfigurationError,
"ApplicationCertificate must be specified.");
}
clientCertificate = appConfig.SecurityConfiguration.ApplicationCertificate.Find(true);
if (clientCertificate == null)
{
Utils.Trace("ApplicationCertificate file could not be found.");
throw ServiceResultException.Create(StatusCodes.BadConfigurationError,
"ApplicationCertificate cannot be found.");
}
}
// Create a transport channel.
return SessionChannel.Create(
appConfig,
endpointDescription,
endpointConfiguration,
clientCertificate,
messageContext);
}
Это сервер возвращает результат BadSecureChannelClosed
? Если да, то почему? Или это одно из множества внутренних исключений, выбрасываемых стеком?