
05/29/2017

Hi, how can the client restore the session (with subscription and monitoredItem inside) on Server after Server restart?
Without create new session, subscription and monitoredItem.
I tried session.Reconnect() but it throw BadSessionIdInvalid exception.
And i tried session.Recreate(session) , in this case ServerState becomes Running, but client not receices event on monitoreItem “Notification” event.
Thanks.

Moderators-Specifications
Moderators-Companion
Moderators-Implementation
Moderators-Certification
Moderators-COM
02/24/2014

If the Server supports “durable subscriptions” then a client can establish a new session and then reclaim the old subscription following a server restart. The client has to establish a new connection to the server with the same security context. The Server should have maintained all data, only loosing any data that changed while it was down/restarting. Durable Subscriptions was a new feature in 1.03.
Paul Hunkar - DSInteroperability

05/29/2017

Thanks for answers!!
In the end i recreated session and subscription.
Added the list of MonitoredItem (that i had previously stored in a List) at new subscription.
But i noticed that MonitoredItems were not created on Server at subscription.Create() time because they had a monitoredItem.Status.Created = true.
I think that I’ve used a workaroud: i’ve call monitoredItem.SetDeleteResult(new StatusCode(1),nothing,Nothing,nothing) foreach monitoredItem before adding them to subscription.
Now, all works fine!

It seems that your issues relate to the UA Software you are using. If you use UA Software from the OPC Foundation public source repositories (e.g. https://github.com/OPCFoundati…..ardLibrary) please enter an issue into the issue list of this repository.
The moderators of this forum have good knowledge of the OPC UA standard but not necessarily of the implementations.

10/12/2015

Hei,
A related question.
I am building a OPC UA Client. I am able to create a subscription containing some Monitoreditems.
On the OPC UA server these monitored items change value constantly.
I want to disconnect the client and wait for a while. Then I reconnect having my subscriptions back, but I also want all the monitored Item values queued up during the disconnect.
I am settin a queuesize:
monitoredItem.QueueSize = 100;
How to capture the content of the queue after a disconnect???
if (node.Displayname == “The node I want to monitor”)
{
MonitoredItem mon = CreateMonitoredItem((NodeId)node.reference.NodeId, node.Displayname);
m_subscription.AddItem(mon);
m_subscription.ApplyChanges();
subscribedClientNodes.Add(node);
}
————
private MonitoredItem CreateMonitoredItem(NodeId nodeId, string displayName)
{
if (m_subscription == null)
{
m_subscription = new Subscription(m_session.DefaultSubscription);
m_subscription.PublishingEnabled = true;
m_subscription.PublishingInterval = 3000;//1000;
m_subscription.KeepAliveCount = 10;
m_subscription.LifetimeCount = 10;
m_subscription.MaxNotificationsPerPublish = 1000;
m_subscription.Priority = 100;
bool cache = m_subscription.DisableMonitoredItemCache;
m_session.AddSubscription(m_subscription);
m_subscription.Create();
}
// add the new monitored item.
MonitoredItem monitoredItem = new MonitoredItem(m_subscription.DefaultItem);
//Each time a monitored item is sampled, the server evaluates the sample using a filter defined for each monitoreditem.
//The server uses the filter to determine if the sample should be reported. The type of filter is dependent on the type of item.
//DataChangeFilter for Variable, Eventfilter when monitoring Events. etc
//MonitoringFilter f = new MonitoringFilter();
//DataChangeFilter f = new DataChangeFilter();
//f.DeadbandValue
monitoredItem.StartNodeId = nodeId;
monitoredItem.AttributeId = Attributes.Value;
monitoredItem.DisplayName = displayName;
//Disabled, Sampling, (Report (includes sampling))
monitoredItem.MonitoringMode = MonitoringMode.Reporting;
//How often the Client wish to check for new values on the server. Must be 0 if item is an event.
//If a negative number the SamplingInterval is set equal to the PublishingInterval (inherited)
//The Subscriptions KeepAliveCount should always be longer than the SamplingInterval/PublishingInterval
monitoredItem.SamplingInterval = 500;
//Number of samples stored on the server between each reporting
monitoredItem.QueueSize = 100;
monitoredItem.DiscardOldest = true;//Discard oldest values when full
monitoredItem.CacheQueueSize = 100;
monitoredItem.Notification += m_MonitoredItem_Notification;
if (ServiceResult.IsBad(monitoredItem.Status.Error))
{
return null;
}
return monitoredItem;
}
——
private void MonitoredItem_Notification(MonitoredItem monitoredItem, MonitoredItemNotificationEventArgs e)
{
if (this.InvokeRequired)
{
this.BeginInvoke(new MonitoredItemNotificationEventHandler(MonitoredItem_Notification), monitoredItem, e);
return;
}
try
{
if (m_session == null)
{
return;
}
MonitoredItemNotification notification = e.NotificationValue as MonitoredItemNotification;
if (notification == null)
{
return;
}
foreach(MonitoredItem mon in monitoredItem.Subscription.MonitoredItems)
{
MonitoredItemNotification v = mon.LastValue as MonitoredItemNotification;
richTextBox1.AppendText(“
Iteration: ” + mon.DisplayName + ” value: ” + v.Value.Value + “sTime: “+v.Value.SourceTimestamp+” status: ” + mon.Status.QueueSize.ToString());
}
string sess = m_session.SessionId.Identifier.ToString();
string s = string.Format(“
MonitoredItem: {0}\t Value: {1}\t Status: {2}\t SourceTimeStamp: {3}”, monitoredItem.DisplayName, (notification.Value.WrappedValue.ToString().Length == 1) ? notification.Value.WrappedValue.ToString() + ” ” : notification.Value.WrappedValue.ToString(), notification.Value.StatusCode.ToString(), notification.Value.SourceTimestamp.ToLocalTime().ToString(“HH:mm:ss.fff”));
richTextBox1.AppendText(s + “
SessionId: ” + sess);
}
catch (Exception exception)
{
ClientUtils.HandleException(this.Text, exception);
}
}
Moderators-Specifications
04/15/2014

In order for a Client to completely disconnect from a Server and later reconnect to a previous Subscription and retrieve the queued values:
- The Server must support the feature “durable Subscriptions” (not many Servers support this feature !!!)
- The Client must explicitly set the Subscription durable by calling the SetSubscriptionDurable Method.
See Clause 6.8 of OPC UA Part 4 https://opcfoundation.org/UA/Part4/ for more details to use this feature.

10/12/2015

Hi Jim,
Thanks for your reply!
Had a look in chapter 6.8 like you said.
Durable subscription seems like what I really need!
Actually I’m creating both the OPC UA server and client so I would have to implement the Durable subscription myself then.
You mentioned not many servers support this feature….I agree. I have been searching for a while to see any examples on how to implement this from the .NET C# SDK. Not found anything yet!!!
If anyone have some more details or examples on implementation I would be very happy!
Thanks!
1 Guest(s)