TransferSubscription

Questions regarding the use of the .NET SDK 2.0 for Server or Client development or integration into customer products ...

Moderator: uasdknet

Post Reply
Erlemeyer
Jr. Member
Jr. Member
Posts: 1
Joined: 07 Jun 2016, 11:14

TransferSubscription

Post by Erlemeyer »

Hello,
we have implemented an OPC UA client in .Net and we want to use the TransferSubscription Service to move the available subscriptions on an OPC UA server to the new session after the restart of the program.
The ID's of the subscriptions already known after the restart of the program.
We want to test your SDK (Version 2.4.2.373) before we implemented this functionality. I found no sample for this topic and there raised an exception, if I call the Transfersubscriptions of the session class.
I used your BasicClient_VS2012.sln for testing.
I have changed the connect method of the MainForm as follows:

/// <summary>
/// Connect to the UA server and read the namespace table.
/// The connect is based on the Server URL entered in the Form
/// The read of the namespace table is used to detect the namespace index
/// of the namespace URI entered in the Form and used for the variables to read
/// </summary>
private void connect()
{
.
.
.
m_session.UserIdentity = new UserIdentity();
m_session.UserIdentity.IdentityType = UserIdentityType.UserName;
m_session.UserIdentity.UserName = username;
m_session.UserIdentity.Password = password;
.
.
.
m_session.Connect(txtServerUrl.Text, SecuritySelection.BestAvailable);
.
.
.
}

After the connection to the UA Demo Server, I create the subscription by pressing the "Monitor" button. After this, the subscriptionId is saved. Now I execute the program and the session always available in the OPC UA Server.
After the restart and new connect to the UA Demo Server I pressed our new button "TransferSubscriptions" with the following code on the click event:

private void btnTransferSubscriptins_Click(object sender, EventArgs e)
{
uint subscriptionId = Convert.ToUInt32(txtSubscriptionId.Text);
if (subscriptionId != 0)
{
IList<uint> subscriptionList = new List<uint> { subscriptionId };
List<TransferResult> result = m_session.TransferSubscriptions(subscriptionList, false, null);
}
}
Then a nullReferenceExeption raised:
Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.

STACK TRACE

bei UnifiedAutomation.UaClient.Session.BeginTransferSubscriptions(TransferSubscriptionsAsyncResult ar)
bei UnifiedAutomation.UaClient.Session.BeginTransferSubscriptions(IList`1 subscriptionsToTransfer, Boolean sendInitialValues, RequestSettings settings, AsyncCallback callback, Object userData)
bei UnifiedAutomation.UaClient.Session.TransferSubscriptions(IList`1 subscriptionsToTransfer, Boolean sendInitialValues, RequestSettings settings)
bei UnifiedAutomation.Sample.MainForm.btnTransferSubscriptins_Click(Object sender, EventArgs e) in D:\Scada\net\HST.SCADA.OPC.UA\OPC UA\BasicClient\MainForm.cs:Zeile 866.
bei System.Windows.Forms.Control.OnClick(EventArgs e)
bei System.Windows.Forms.Button.OnClick(EventArgs e)
bei System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
bei System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
bei System.Windows.Forms.Control.WndProc(Message& m)
bei System.Windows.Forms.ButtonBase.WndProc(Message& m)
bei System.Windows.Forms.Button.WndProc(Message& m)
bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
bei UnifiedAutomation.Sample.Program.Run(Object userState) in D:\Scada\net\HST.SCADA.OPC.UA\OPC UA\BasicClient\Program.cs:Zeile 75.
bei UnifiedAutomation.UaBase.ApplicationInstance.Start(ServerBase server, WaitCallback callback, Object userData)
bei UnifiedAutomation.UaBase.ApplicationInstance.Start(WaitCallback callback, Object userData)
bei UnifiedAutomation.Sample.Program.Main() in D:\Scada\net\HST.SCADA.OPC.UA\OPC UA\BasicClient\Program.cs:Zeile 59.

Is there a sample how I use these functionality in a rigth way?

User avatar
Support Team
Hero Member
Hero Member
Posts: 3072
Joined: 18 Mar 2011, 15:09

Re: TransferSubscription

Post by Support Team »

Explicit calling of TransferSubscription is not supported in the current version of the SDK. TransferSubscriptions is called internally when reconnecting after connection losses.
Best regards
Unified Automation Support Team

Post Reply