.NET Based OPC UA Client/Server SDK  3.1.0.500
Connect – Reverse Connect

Description

The following dialog shows an implementation of the Reverse Connect service. Press the button “Show Code” to display the corresponding code, and the button “Help” to show this documentation page.

Note
Before start make sure Reverse Connect is configured in your server. For information how to configure a server look here.
At start, a new session with reverse connetion features is opened. The session will be created with Client Listening URL as parameter. To listen to another URL change the defaultClientListeningURL in ReverseConnectDialog.cs. The settings performed using this dialog window do not affect the other Getting Started Examples.
clienttutorials_reverse_connect.png

This example is similar to Advanced Connect. The connection is not established automatically and requires user interaction.

After session creation the client automatically looks for open server channels on the given URL.

Now the following connection process is nearly the same as a normal forward connect.

Enter the servers endpoint URL into "Server URL". By default, this is the Unified Automation .NET Demo Server running on localhost.

Click on “Get Endpoints” to request a list of available Endpoints from the server. Check the box at “Use Asynchronous Pattern” to call BeginGetEndpoints instead of GetEndpoints.

The server’s response is then displayed as a table at “Get Endpoints Response” (see screenshot below).

clienttutorials_reverse_connect2.png

Double-click on an entry to display more detailed information for a certain Endpoint.

clienttutorials_reverse_connect3.png

Select an Endpoint from the list and click on “Connect” to establish a reverse connection. When choosing a secure endpoint, it is necessary that client and server trust each other’s certificate first (as described in in the simple connect example).

If successful, the displayed connection state will switch to “Connected”. Check the box at “Use Asynchronous Pattern” to call BeginReverseConnect instead of ReverseConnect.

clienttutorials_reverse_connect4.png

Sample Code

The following code only shows differenses to the forward connect. For forward connect examples look Advanced Connect.

Create new session with the URL the server is providing channels at.

m_session = new Session(m_parent.Application, defaultClientListeningURL);

Call ReverseConnect with one of the returned endpoints.

m_session.ReverseConnect(SelectedEndpoint, m_session.DefaultRequestSettings);

A callback (OnConnectCompleted) and user data (session) are passed to BeginReverseConnect. The callback casts the user data and calls End Connect.

private void BeginReverseConnect()
{
try
{
m_session.BeginReverseConnect(
SelectedEndpoint,
m_session.DefaultRequestSettings,
OnReverseConnectCompleted,
m_session);
}
catch (Exception e)
{
ExceptionDlg.ShowInnerException(this.Text, e);
}
}
private void OnReverseConnectCompleted(IAsyncResult result)
{
// need to make sure the results are processed on the correct thread.
if (InvokeRequired)
{
BeginInvoke(new AsyncCallback(OnReverseConnectCompleted), result);
return;
}
// get the session used to send the request which was passed as the userData in the Begin call.
Session session = (Session)result.AsyncState;
try
{
session.EndReverseConnect(result);
}
catch (Exception e)
{
ExceptionDlg.ShowInnerException(this.Text, e);
}
}