QuickOPC User's Guide and Reference
UAServerOnNetwork Class
Members 



OpcLabs.EasyOpcUA Assembly > OpcLabs.EasyOpc.UA.Discovery Namespace : UAServerOnNetwork Class
A DNS service record for OPC Unified Architecture (OPC UA).
Object Model
UAServerOnNetwork ClassStringCollection Class
Syntax
'Declaration
 
<CLSCompliantAttribute(True)>
<ComDefaultInterfaceAttribute(OpcLabs.EasyOpc.UA.Discovery.ComTypes._UAServerOnNetwork)>
<ComVisibleAttribute(True)>
<GuidAttribute("2746D7F4-BA66-4275-9213-07BD6C407876")>
<TypeConverterAttribute(System.ComponentModel.ExpandableObjectConverter)>
<ValueControlAttribute("OpcLabs.BaseLib.Forms.Common.ObjectSerializationControl, OpcLabs.BaseLibForms, Version=5.72.465.1, Culture=neutral, PublicKeyToken=6faddca41dacb409", 
   DefaultReadWrite=False, 
   Export=True, 
   PageId=10001)>
<SerializableAttribute()>
Public Class UAServerOnNetwork 
   Inherits OpcLabs.BaseLib.Info
   Implements LINQPad.ICustomMemberProvider, OpcLabs.BaseLib.ComTypes._Info, OpcLabs.BaseLib.ComTypes._Object2, OpcLabs.EasyOpc.UA.Discovery.ComTypes._UAServerOnNetwork, System.ICloneable, System.Runtime.Serialization.ISerializable, System.Xml.Serialization.IXmlSerializable 
'Usage
 
Dim instance As UAServerOnNetwork
[CLSCompliant(true)]
[ComDefaultInterface(OpcLabs.EasyOpc.UA.Discovery.ComTypes._UAServerOnNetwork)]
[ComVisible(true)]
[Guid("2746D7F4-BA66-4275-9213-07BD6C407876")]
[TypeConverter(System.ComponentModel.ExpandableObjectConverter)]
[ValueControl("OpcLabs.BaseLib.Forms.Common.ObjectSerializationControl, OpcLabs.BaseLibForms, Version=5.72.465.1, Culture=neutral, PublicKeyToken=6faddca41dacb409", 
   DefaultReadWrite=false, 
   Export=true, 
   PageId=10001)]
[Serializable()]
public class UAServerOnNetwork : OpcLabs.BaseLib.Info, LINQPad.ICustomMemberProvider, OpcLabs.BaseLib.ComTypes._Info, OpcLabs.BaseLib.ComTypes._Object2, OpcLabs.EasyOpc.UA.Discovery.ComTypes._UAServerOnNetwork, System.ICloneable, System.Runtime.Serialization.ISerializable, System.Xml.Serialization.IXmlSerializable  
[CLSCompliant(true)]
[ComDefaultInterface(OpcLabs.EasyOpc.UA.Discovery.ComTypes._UAServerOnNetwork)]
[ComVisible(true)]
[Guid("2746D7F4-BA66-4275-9213-07BD6C407876")]
[TypeConverter(System.ComponentModel.ExpandableObjectConverter)]
[ValueControl("OpcLabs.BaseLib.Forms.Common.ObjectSerializationControl, OpcLabs.BaseLibForms, Version=5.72.465.1, Culture=neutral, PublicKeyToken=6faddca41dacb409", 
   DefaultReadWrite=false, 
   Export=true, 
   PageId=10001)]
[Serializable()]
public ref class UAServerOnNetwork : public OpcLabs.BaseLib.Info, LINQPad.ICustomMemberProvider, OpcLabs.BaseLib.ComTypes._Info, OpcLabs.BaseLib.ComTypes._Object2, OpcLabs.EasyOpc.UA.Discovery.ComTypes._UAServerOnNetwork, System.ICloneable, System.Runtime.Serialization.ISerializable, System.Xml.Serialization.IXmlSerializable  
Remarks

A list of these objects is returned by the OpcLabs.EasyOpc.UA.Gds.IEasyUAGlobalDiscoveryClient.QueryServers method.

 

QuickOPC-UA allows you to obtain information about OPC UA servers from a Local Discovery Server with Multicast Extensions (LDS-ME), which uses the mDNS protocol to exchange the information about OPC UA servers with other LDS-ME-s on the network (or multiple networks).

In .NET, if you want to retrieve a list of OPC Unified Architecture servers available on your network, call the DiscoverNetworkServers method without further parameters. This will obtain the information about servers using the LDS-ME installed on the machine where the component is running, and without further restricting (filtering) them.

Further in .NET, if you want to retrieve a list of OPC Unified Architecture servers available on your network, call the DiscoverNetworkServers method with one or two arguments, passing it

In COM, the DiscoverNetworkServers method has two arguments, and therefore if you want no filtering, pass a null reference (or an empty collection) as the first argument, and pass "localhost" as the second argument if you want to use the LDS-ME installed on your machine.

In all cases described above, you will receive back a UADiscoveryElementCollection object, which is collection of UADiscoveryElement-s. Each element contains a server's discovery URL. The discovery URL is the main piece of information that you can further use if you want to connect to that OPC-UA server. Each UADiscoveryElement contains information gathered about one OPC server found by the discovery process, including things like the server name, application type, and - mainly - its DiscoveryUriString.

.NET

// This example shows how to obtain information about OPC UA servers available on the network.
// The result is flat, i.e. each discovery URL is returned in separate element, with possible repetition of the servers.

using System;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.Discovery;
using OpcLabs.EasyOpc.UA.OperationModel;

namespace UADocExamples._EasyUAClient
{
    partial class DiscoverNetworkServers
    {
        public static void Main1()
        {
            // Instantiate the client object.
            var client = new EasyUAClient();

            // Obtain collection of application elements.
            UADiscoveryElementCollection discoveryElementCollection;
            try
            {
                discoveryElementCollection = client.DiscoverNetworkServers("opcua.demo-this.com");
            }
            catch (UAException uaException)
            {
                Console.WriteLine($"*** Failure: {uaException.GetBaseException().Message}");
                return;
            }

            // Display results.
            foreach (UADiscoveryElement discoveryElement in discoveryElementCollection)
            {
                Console.WriteLine();
                Console.WriteLine($"Server name: {discoveryElement.ServerName}");
                Console.WriteLine($"Discovery URI string: {discoveryElement.DiscoveryUriString}");
                Console.WriteLine($"Server capabilities: {discoveryElement.ServerCapabilities}");
                Console.WriteLine($"Application URI string: {discoveryElement.ApplicationUriString}");
                Console.WriteLine($"Product URI string: {discoveryElement.ProductUriString}");
            }
        }
    }
}
# This example shows how to obtain information about OPC UA servers available on the network.
# The result is flat, i.e. each discovery URL is returned in separate element, with possible repetition of the servers.

#requires -Version 5.1
using namespace OpcLabs.EasyOpc.UA
using namespace OpcLabs.EasyOpc.UA.Discovery
using namespace OpcLabs.EasyOpc.UA.OperationModel

# The path below assumes that the current directory is [ProductDir]/Examples-NET/PowerShell/Windows .
Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcUA.dll"
Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcUAComponents.dll"

# Instantiate the client object.
$client = New-Object EasyUAClient

# Obtain collection of application elements.
try {
    $discoveryElementCollection = [IEasyUAClientExtension]::DiscoverNetworkServers($client, "opcua.demo-this.com")
}
catch [UAException] {
    Write-Host "*** Failure: $($PSItem.Exception.GetBaseException().Message)"
    return
}

# Display results.
foreach ($discoveryElement in $discoveryElementCollection) {
    Write-Host
    Write-Host "Server name: $($discoveryElement.ServerName)"
    Write-Host "Discovery URI string: $($discoveryElement.DiscoveryUriString)"
    Write-Host "Server capabilities: $($discoveryElement.ServerCapabilities)"
    Write-Host "Application URI string: $($discoveryElement.ApplicationUriString)"
    Write-Host "Product URI string: $($discoveryElement.ProductUriString)"
}
# This example shows how to obtain information about OPC UA servers available on the network.
# The result is flat, i.e. each discovery URL is returned in separate element, with possible repetition of the servers.

# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc

# Import .NET namespaces.
from OpcLabs.EasyOpc.UA import *
from OpcLabs.EasyOpc.UA.Discovery import *
from OpcLabs.EasyOpc.UA.OperationModel import *


# Instantiate the client object.
client = EasyUAClient()

# Obtain collection of application elements.
try:
    discoveryElementCollection = IEasyUAClientExtension.DiscoverNetworkServers(client, 'opcua.demo-this.com')
except UAException as uaException:
    print('*** Failure: ' + uaException.GetBaseException().Message)
    exit()

# Display results.
for discoveryElement in discoveryElementCollection:
    print()
    print('Server name: ', discoveryElement.ServerName, sep='')
    print('Discovery URI string: ', discoveryElement.DiscoveryUriString, sep='')
    print('Server capabilities: ', discoveryElement.ServerCapabilities, sep='')
    print('Application URI string: ', discoveryElement.ApplicationUriString, sep='')
    print('Product URI string: ', discoveryElement.ProductUriString, sep='')

print()
print('Finished.')
' This example shows how to obtain information about OPC UA servers available on the network.
' The result is flat, i.e. each discovery URL is returned in separate element, with possible repetition of the servers.

Imports OpcLabs.EasyOpc.UA
Imports OpcLabs.EasyOpc.UA.Discovery
Imports OpcLabs.EasyOpc.UA.OperationModel

Namespace _EasyUAClient
    Partial Friend Class DiscoverNetworkServers
        Public Shared Sub Main1()
            ' Instantiate the client object
            Dim client = New EasyUAClient()

            ' Obtain collection of application elements
            Dim discoveryElementCollection As UADiscoveryElementCollection
            Try
                discoveryElementCollection = client.DiscoverNetworkServers("opcua.demo-this.com")
            Catch uaException As UAException
                Console.WriteLine("*** Failure: {0}", uaException.GetBaseException.Message)
                Exit Sub
            End Try

            ' Display results
            For Each discoveryElement As UADiscoveryElement In discoveryElementCollection
                Console.WriteLine()
                Console.WriteLine("Server name: {0}", discoveryElement.ServerName)
                Console.WriteLine("Discovery URI string: {0}", discoveryElement.DiscoveryUriString)
                Console.WriteLine("Server capabilities: {0}", discoveryElement.ServerCapabilities)
                Console.WriteLine("Application URI string: {0}", discoveryElement.ApplicationUriString)
                Console.WriteLine("Product URI string: {0}", discoveryElement.ProductUriString)
            Next discoveryElement
        End Sub
    End Class
End Namespace

COM

// This example shows how to obtain information about OPC UA servers available on the network.

class procedure DiscoverNetworkServers.Main;
var
  Client: OpcLabs_EasyOpcUA_TLB._EasyUAClient;
  Count: Cardinal;
  Element: OleVariant;
  DiscoveryElement: _UADiscoveryElement;
  DiscoveryElementEnumerator: IEnumVariant;
  DiscoveryElements: _UADiscoveryElementCollection;
begin
  // Instantiate the client object
  Client := CoEasyUAClient.Create;

  // Obtain collection of application elements
  try
    DiscoveryElements := Client.DiscoverNetworkServers(Unassigned, 'opcua.demo-this.com');
  except
    on E: EOleException do
    begin
      WriteLn(Format('*** Failure: %s', [E.GetBaseException.Message]));
      Exit;
    end;
  end;

  // Display results
  DiscoveryElementEnumerator := DiscoveryElements.GetEnumerator;
  while (DiscoveryElementEnumerator.Next(1, Element, Count) = S_OK) do
  begin
    DiscoveryElement := IUnknown(Element) as _UADiscoveryElement;
    WriteLn;
    WriteLn('Server name: ', DiscoveryElement.ServerName);
    WriteLn('Discovery URI string: ', DiscoveryElement.DiscoveryUriString);
    WriteLn('Server capabilities: ', DiscoveryElement.ServerCapabilities.ToString);
  end;
end;
// This example shows how to obtain information about OPC UA servers available on the network.

#include "stdafx.h"    // Includes "QuickOpc.h", and other commonly used files
#include "DiscoverNetworkServers.h"

namespace _EasyUAClient
{
    void DiscoverNetworkServers::Main()
    {
        // Initialize the COM library
        CoInitializeEx(NULL, COINIT_MULTITHREADED);
        {
            // Instantiate the client object
            _EasyUAClientPtr ClientPtr(__uuidof(EasyUAClient));

            _StringCollectionPtr ServerElementFilterPtr(__uuidof(StringCollection));
            _variant_t vServerElementFilter(ServerElementFilterPtr.GetInterfacePtr());

            // Obtain collection of application elements
            _UADiscoveryElementCollectionPtr DiscoveryElementsPtr = 
                ClientPtr->DiscoverNetworkServers(vServerElementFilter, L"opcua.demo-this.com");
    
            // Display results
            IEnumVARIANTPtr EnumDiscoveryElementPtr = DiscoveryElementsPtr->GetEnumerator();
            _variant_t vDiscoveryElement;
            while (EnumDiscoveryElementPtr->Next(1, &vDiscoveryElement, NULL) == S_OK)
            {
                _UADiscoveryElementPtr DiscoveryElementPtr(vDiscoveryElement);
                _tprintf(_T("\n"));
                _tprintf(_T("Application type: %d\n"), DiscoveryElementPtr->ApplicationType);
                _tprintf(_T("Server name: %s\n"), (LPCTSTR)CW2CT(DiscoveryElementPtr->ServerName));
                _tprintf(_T("Discovery URI string: %s\n"), (LPCTSTR)CW2CT(DiscoveryElementPtr->DiscoveryUriString));
                _tprintf(_T("Server capabilities: "));
                IEnumVARIANTPtr EnumServerCapabilityPtr = DiscoveryElementPtr->ServerCapabilities->GetEnumerator();
                _variant_t vServerCapability = NULL;
                while (EnumServerCapabilityPtr->Next(1, &vServerCapability, NULL) == S_OK)
                    _tprintf(_T("%s "), (LPCTSTR)CW2CT(_bstr_t(vServerCapability)));
                _tprintf(_T("\n"));
                vDiscoveryElement.Clear();
            }
        }
         // Release all interface pointers BEFORE calling CoUninitialize()
        CoUninitialize();
    }
}
Rem This example shows how to obtain information about OPC UA servers available on the network.

Public Sub DiscoverNetworkServers_Main_Command_Click()
    OutputText = ""

    ' Instantiate the client object
    Dim Client As New EasyUAClient

    ' Obtain collection of application elements
    On Error Resume Next
    Dim DiscoveryElementCollection As UADiscoveryElementCollection
    Set DiscoveryElementCollection = Client.DiscoverNetworkServers(Nothing, "opcua.demo-this.com")
    If Err.Number <> 0 Then
        OutputText = OutputText & "*** Failure: " & Err.Source & ": " & Err.Description & vbCrLf
        Exit Sub
    End If
    On Error GoTo 0
    
    ' Display results
    Dim DiscoveryElement As UADiscoveryElement: For Each DiscoveryElement In DiscoveryElementCollection
        OutputText = OutputText & vbCrLf
        OutputText = OutputText & "Server name: " & DiscoveryElement.ServerName & vbCrLf
        OutputText = OutputText & "Discovery URI string: " & DiscoveryElement.DiscoveryUriString & vbCrLf
        OutputText = OutputText & "Server capabilities: " & DiscoveryElement.serverCapabilities.ToString & vbCrLf
    Next
End Sub
Rem This example shows how to obtain information about OPC UA servers available on the network.

Option Explicit

' Instantiate the client object
Dim Client: Set Client = CreateObject("OpcLabs.EasyOpc.UA.EasyUAClient")

' Obtain collection of application elements
On Error Resume Next
Dim DiscoveryElementCollection: Set DiscoveryElementCollection = _
    Client.DiscoverNetworkServers(Nothing, "opcua.demo-this.com")
If Err.Number <> 0 Then
    WScript.Echo "*** Failure: " & Err.Source & ": " & Err.Description
    WScript.Quit
End If
On Error Goto 0

' Display results
Dim DiscoveryElement: For Each DiscoveryElement In DiscoveryElementCollection
    WScript.Echo
    WScript.Echo "Server name: " & DiscoveryElement.ServerName
    WScript.Echo "Discovery URI string: " & DiscoveryElement.DiscoveryUriString
    Dim s: s = ""
    Dim serverCapability: For Each serverCapability In DiscoveryElement.ServerCapabilities
        s = s & serverCapability & " "
    Next
    WScript.Echo "Server capabilities: " & s
Next

You can also obtain the results unflattened:

// This example shows how to obtain information about OPC UA servers available on the network.
// The result is hierarchical, i.e. each server is returned in one element, and the element contains all its discovery URLs.

using System;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.Discovery;
using OpcLabs.EasyOpc.UA.OperationModel;

namespace UADocExamples._EasyUAClient
{
    partial class DiscoverNetworkServers
    {
        public static void Hierarchical()
        {
            // Instantiate the client object
            var client = new EasyUAClient();

            // Obtain collection of application elements
            UADiscoveryElementCollection discoveryElementCollection;
            try
            {
                discoveryElementCollection = client.DiscoverNetworkServers("opcua.demo-this.com", flat:false);
            }
            catch (UAException uaException)
            {
                Console.WriteLine("*** Failure: {0}", uaException.GetBaseException().Message);
                return;
            }

            // Display results
            foreach (UADiscoveryElement discoveryElement in discoveryElementCollection)
            {
                Console.WriteLine();
                Console.WriteLine("Server name: {0}", discoveryElement.ServerName);
                Console.WriteLine("Discovery URI strings:");
                foreach (string discoveryUriString in discoveryElement.DiscoveryUriStrings)
                    Console.WriteLine("  {0}", discoveryUriString);
                Console.WriteLine("Server capabilities: {0}", discoveryElement.ServerCapabilities);
            }
        }
    }
}
# This example shows how to obtain information about OPC UA servers available on the network.
# The result is hierarchical, i.e. each server is returned in one element, and the element contains all its discovery
# URLs.

# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc

# Import .NET namespaces.
from OpcLabs.EasyOpc.UA import *
from OpcLabs.EasyOpc.UA.Discovery import *
from OpcLabs.EasyOpc.UA.OperationModel import *


# Instantiate the client object.
client = EasyUAClient()

# Obtain collection of application elements.
try:
    discoveryElementCollection = IEasyUAClientExtension.DiscoverNetworkServers(client,
        'opcua.demo-this.com',
        False) # flat=False
except UAException as uaException:
    print('*** Failure: ' + uaException.GetBaseException().Message)
    exit()

# Display results.
for discoveryElement in discoveryElementCollection:
    print()
    print('Server name: ', discoveryElement.ServerName, sep='')
    print('Discovery URI strings:')
    for discoveryUriString in discoveryElement.DiscoveryUriStrings:
        print('  ', discoveryUriString, sep='')
    print('Server capabilities: ', discoveryElement.ServerCapabilities, sep='')

print()
print('Finished.')
' This example shows how to obtain information about OPC UA servers available on the network.
' The result is hierarchical, i.e. each server is returned in one element, and the element contains all its discovery URLs.

Imports OpcLabs.EasyOpc.UA
Imports OpcLabs.EasyOpc.UA.Discovery
Imports OpcLabs.EasyOpc.UA.OperationModel

Namespace _EasyUAClient
    Partial Friend Class DiscoverNetworkServers
        Public Shared Sub Hierarchical()
            ' Instantiate the client object
            Dim client = New EasyUAClient()

            ' Obtain collection of application elements
            Dim discoveryElementCollection As UADiscoveryElementCollection
            Try
                discoveryElementCollection = client.DiscoverNetworkServers("opcua.demo-this.com", flat:=False)
            Catch uaException As UAException
                Console.WriteLine("*** Failure: {0}", uaException.GetBaseException.Message)
                Exit Sub
            End Try

            ' Display results
            For Each discoveryElement As UADiscoveryElement In discoveryElementCollection
                Console.WriteLine()
                Console.WriteLine("Server name: {0}", discoveryElement.ServerName)
                Console.WriteLine("Discovery URI strings:")
                For Each discoveryUriString As String In discoveryElement.DiscoveryUriStrings
                    Console.WriteLine("  {0}", discoveryUriString)
                Next discoveryUriString
                Console.WriteLine("Server capabilities: {0}", discoveryElement.ServerCapabilities)
            Next discoveryElement
        End Sub
    End Class
End Namespace

Note that QuickOPC returns UADiscoveryElementCollection from all OPC UA discovery methods, but the amount of information contained in each returned UADiscoveryElement depends on the discovery approach used. For OPC UA Global Discovery and OPC UA Network Discovery, only following primary properties of each UADiscoveryElement are filled in:

OPC UA Local Discovery Server with Multicast Extensions (LDS-ME) is not part of QuickOPC installation.

 

Inheritance Hierarchy

System.Object
   OpcLabs.BaseLib.Object2
      OpcLabs.BaseLib.Info
         OpcLabs.EasyOpc.UA.Discovery.UAServerOnNetwork

Requirements

Target Platforms: .NET Framework: Windows 10 (selected versions), Windows 11 (selected versions), Windows Server 2016, Windows Server 2022; .NET: Linux, macOS, Microsoft Windows

See Also