简体   繁体   English

OPC UA .net标准重新连接

[英]OPC UA .net standard reconnection

I'm working on an opc client using the .net standard stack from the opc foundation. 我正在使用来自opc基金会的.net标准堆栈在opc客户端上工作。 Everything seems to work as expected. 一切似乎都按预期进行。 I can establish a session, add subscriptions, items, get notifications when data changes... 我可以建立会话,添加订阅,项目,并在数据更改时获取通知...

The issue I'm having is I can't find an event in the Session that fires when the Session is closed from the server side. 我遇到的问题是,在会话中,从服务器端关闭会话时无法触发该事件。

I'm testing with Kepserver EX 6. When i reinitialize or turn off the runtime in the server, my SessionClosing event isn't firing, so i supposed the Server isnt notifying the client. 我正在用Kepserver EX 6进行测试。当我重新初始化或关闭服务器中的运行时时,我的SessionClosing事件没有触发,因此我认为服务器未在通知客户端。 I don't know if it would fire after a timeout or something? 我不知道它是否会在超时后触发?

After this, my Opc.Ua.Client.Session object in the client code still shows the Connected property as true. 之后,客户端代码中的Opc.Ua.Client.Session对象仍然将Connected属性显示为true。 Only when when i try do do something like adding a new subscription do i get a Bad session exception . 只有当我尝试执行添加新订阅之类的操作时,我才会收到Bad Session异常。

I could catch the exception and reestablish a new Session or try to fix the current one, but i'd rather know that the Session has gone bad beforehand. 我可以捕捉到异常并重新建立一个新的Session或尝试修复当前的Session,但是我宁愿知道Session事先变坏了。 I don't even know if this is possible. 我什至不知道这是否可能。

Thanks. 谢谢。

wrapped.Create wrapped.Create

This is the config. 这是配置。 I guess i must've picked it from an example: 我想我一定是从一个例子中挑选出来的:

var 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 = @"%CommonApplicationData%\\OPC Foundation\\CertificateStores\\MachineDefault", SubjectName = Utils.Format(@"CN={0}, DC={1}", "MyHomework", System.Net.Dns.GetHostName()) }, TrustedIssuerCertificates = new CertificateTrustList { StoreType = @"Directory", StorePath = @"%CommonApplicationData%\\OPC Foundation\\CertificateStores\\UA Certificate Authorities" }, TrustedPeerCertificates = new CertificateTrustList { StoreType = @"Directory", StorePath = @"%CommonApplicationData%\\OPC Foundation\\CertificateStores\\UA Applications" }, RejectedCertificateStore = new CertificateTrustList { StoreType = @"Directory", StorePath = @"%CommonApplicationData%\\OPC Foundation\\CertificateStores\\RejectedCertificates" }, AutoAcceptUntrustedCertificates = true, AddAppCertToTrustedStore = true, RejectSHA1SignedCertificates = false, MinimumCertificateKeySize = 1024 }, TransportConfigurations = new TransportConfigurationCollection(), TransportQuotas = new TransportQuotas { OperationTimeout = 15000 }, ClientConfiguration = new ClientConfiguration { DefaultSessionTimeout = 60000 }, TraceConfiguration = new TraceConfiguration() }

Then i use the config object in the Session constructor: 然后我在Session构造函数中使用config对象:

Session.Create(config, new ConfiguredEndpoint(null, selectedEndpoint, EndpointConfiguration.Create(config)), false, "", 60000, credentials, null) It seems that 60000 is specified twice. Session.Create(config, new ConfiguredEndpoint(null, selectedEndpoint, EndpointConfiguration.Create(config)), false, "", 60000, credentials, null)似乎两次指定了60000。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM