OPC-UA Client connect Multiple Server|Product and Service Requests|Forum|OPC Foundation

Avatar
Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
Lost password?
sp_Feed sp_PrintTopic sp_TopicIcon
OPC-UA Client connect Multiple Server
Avatar
Karyadi Sulaiman
Member
Members
Forum Posts: 3
Member Since:
11/27/2017
sp_UserOfflineSmall Offline
1
01/14/2021 - 00:29
sp_Permalink sp_Print

Is that possible OPC-UA Client to connect Multiple Server

Avatar
Randy Armstrong
Admin
Forum Posts: 1564
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
2
01/14/2021 - 14:52
sp_Permalink sp_Print

Yes. Clients are only limited by the resources they have.

Avatar
Karyadi Sulaiman
Member
Members
Forum Posts: 3
Member Since:
11/27/2017
sp_UserOfflineSmall Offline
3
01/14/2021 - 19:58
sp_Permalink sp_Print sp_EditHistory

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?
form.jpgImage EnlargerError.jpgImage Enlarger

Avatar
Randy Armstrong
Admin
Forum Posts: 1564
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
4
01/15/2021 - 11:54
sp_Permalink sp_Print

ConnectServerCtrl is sample UI control that is limited to one connection at time.

You have develop your own control if you need to connect to multiple servers at time.

Avatar
Karyadi Sulaiman
Member
Members
Forum Posts: 3
Member Since:
11/27/2017
sp_UserOfflineSmall Offline
5
01/15/2021 - 18:46
sp_Permalink sp_Print

Dear Randy,

I don't know how?

Would you please guide me.

Thanks

Avatar
Randy Armstrong
Admin
Forum Posts: 1564
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
6
01/17/2021 - 09:37
sp_Permalink sp_Print

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.

Forum Timezone: America/Phoenix
Most Users Ever Online: 510
Currently Online: Mohit Agarwal
Guest(s) 25
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Forum Stats:
Groups: 2
Forums: 10
Topics: 1434
Posts: 4854