11/27/2017
Dear Randy,
I want to connect 2 or more OPC-UA Server:
– example: opc.tcp://192.168.137.102 and opc.tcp://192.168.137.103)
– I use Visual studio 2019 C#
– Here is the code:
this.connectServerCtrl1.ServerUrl = “opc.tcp://192.168.137.102”;
string AppName = “testopcua”;
ApplicationConfiguration config = new ApplicationConfiguration()
{
ApplicationName = AppName,
ApplicationUri = Utils.Format(@”urn:{0}:” + AppName, System.Net.Dns.GetHostName()),
ApplicationType = ApplicationType.Client,
SecurityConfiguration = new SecurityConfiguration
{
ApplicationCertificate = new CertificateIdentifier
{
StoreType = @”Directory”,
StorePath = System.Windows.Forms.Application.StartupPath + @”\Cert\TrustedIssuer”,
SubjectName = “CN=” + AppName + “, DC=” + System.Net.Dns.GetHostName()
},
TrustedIssuerCertificates = new CertificateTrustList
{
StoreType = @”Directory”,
StorePath = System.Windows.Forms.Application.StartupPath + @”\Cert\TrustedIssuer”
},
TrustedPeerCertificates = new CertificateTrustList
{
StoreType = @”Directory”,
StorePath = System.Windows.Forms.Application.StartupPath + @”\Cert\TrustedIssuer”
},
RejectedCertificateStore = new CertificateTrustList
{
StoreType = @”Directory”,
StorePath = System.Windows.Forms.Application.StartupPath + @”\Cert\RejectedCertificates”
},
AutoAcceptUntrustedCertificates = true, //true
AddAppCertToTrustedStore = true, //true
RejectSHA1SignedCertificates = false//important
},
TransportConfigurations = new TransportConfigurationCollection(),
TransportQuotas = new TransportQuotas { OperationTimeout = 15000 },
ClientConfiguration = new ClientConfiguration { DefaultSessionTimeout = 60000 },
TraceConfiguration = new TraceConfiguration
{
DeleteOnLoad = true
},
DisableHiResClock = false
};
config.Validate(ApplicationType.Client).GetAwaiter().GetResult();
if (config.SecurityConfiguration.AutoAcceptUntrustedCertificates)
{
config.CertificateValidator.CertificateValidation += (s, ee) =>
{ ee.Accept = (ee.Error.StatusCode == StatusCodes.BadCertificateUntrusted); };
}
this.connectServerCtrl1.Configuration = config;
this.connectServerCtrl1.UserIdentity = new UserIdentity();
this.connectServerCtrl1.UseSecurity = true;
var application = new ApplicationInstance
{
ApplicationName = AppName,
ApplicationType = ApplicationType.Client,
ApplicationConfiguration = config
};
Opc.Ua.Utils.SetTraceMask(0);//
application.CheckApplicationInstanceCertificate(true, 2048).GetAwaiter().GetResult();//create certificate
connectServerCtrl1.Connect();
}
My questions:
1. how to add more connectServerCtrl1.ServerUrl address and Session for another OPC-UA Server?
2. How to add more Opc.Ua.Client.Controls.ConnectServerCtrl in Windows Form,
because there is an error ‘Failed to create component’ when I add more connectServerCtrl?
05/30/2017
You can find a non-gui example here:
https://github.com/OPCFoundati…..soleClient
That should give you the basis for a function/class that can used to connect to a single server.
Call it multiple times to connect to multiple servers.
1 Guest(s)