OPC Studio User's Guide and Reference
DiscoverGlobalServers() Method
Example 



OpcLabs.EasyOpcUA Assembly > OpcLabs.EasyOpc.UA Namespace > EasyUAClientCore Class > DiscoverGlobalServers Method : DiscoverGlobalServers() Method
Globally discovers OPC-UA servers and returns information about them, using an empty filter, and the default GDS endpoint.
Syntax
'Declaration
 
<ElementsNotNullAttribute()>
<NotNullAttribute()>
Public Overloads Function DiscoverGlobalServers() As UADiscoveryElementCollection
'Usage
 
Dim instance As EasyUAClientCore
Dim value As UADiscoveryElementCollection
 
value = instance.DiscoverGlobalServers()
[ElementsNotNull()]
[NotNull()]
public UADiscoveryElementCollection DiscoverGlobalServers()
[ElementsNotNull()]
[NotNull()]
public:
UADiscoveryElementCollection^ DiscoverGlobalServers(); 

Return Value

Returns a collection of application elements (usually servers, OpcLabs.EasyOpc.UA.Discovery.UADiscoveryElement).
Remarks

This method uses the so-called OPC UA Global Discovery Server (GDS).

Example

.NET

COM

.NET

// This example shows how to obtain information about OPC UA servers from the Global Discovery Server (GDS).
// The result is flat, i.e. each discovery URL is returned in separate element, with possible repetition of the servers.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

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

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

            // Obtain collection of application elements.
            UADiscoveryElementCollection discoveryElementCollection;
            try
            {
                discoveryElementCollection = client.DiscoverGlobalServers(
                    "opc.tcp://opcua.demo-this.com:58810/GlobalDiscoveryServer");
            }
            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}");
            }
        }
    }
}
# This example shows how to obtain information about OPC UA servers from the Global Discovery Server (GDS).
# The result is flat, i.e. each discovery URL is returned in separate element, with possible repetition of the servers.
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

#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]::DiscoverGlobalServers($client,
        "opc.tcp://opcua.demo-this.com:58810/GlobalDiscoveryServer")
}
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)"
}


# Example output:
#
# This example shows how to obtain information about OPC UA servers from the Global Discovery Server (GDS).
# The result is flat, i.e. each discovery URL is returned in separate element, with possible repetition of the servers.
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
# OPC client and subscriber examples in Python on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-Python .
# 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.DiscoverGlobalServers(client,
        UAEndpointDescriptor('opc.tcp://opcua.demo-this.com:58810/GlobalDiscoveryServer'))
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()
print('Finished.')
' This example shows how to obtain information about OPC UA servers from the Global Discovery Server (GDS).
' The result is flat, i.e. each discovery URL is returned in separate element, with possible repetition of the servers.
'
' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

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

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

            ' Obtain collection of application elements
            Dim discoveryElementCollection As UADiscoveryElementCollection
            Try
                discoveryElementCollection = client.DiscoverGlobalServers("opc.tcp://opcua.demo-this.com:58810/GlobalDiscoveryServer")
            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)
            Next discoveryElement
        End Sub
    End Class
End Namespace
// This example shows how to obtain information about OPC UA servers from the Global Discovery Server (GDS).
// The result is flat, i.e. each discovery URL is returned in separate element, with possible repetition of the servers.
//
// Find all latest examples here : https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

class procedure DiscoverGlobalServers.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.DiscoverGlobalServers('opc.tcp://opcua.demo-this.com:58810/GlobalDiscoveryServer');
  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;
REM This example shows how to obtain information about OPC UA servers from the Global Discovery Server (GDS).
REM The result is flat, i.e. each discovery URL is returned in separate element, with possible repetition of the servers.
REM
REM Find all latest examples here : https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

Public Sub DiscoverGlobalServers_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.DiscoverGlobalServers("opc.tcp://opcua.demo-this.com:58810/GlobalDiscoveryServer")
    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
// This example shows how to obtain information about OPC UA servers from the Global Discovery Server (GDS).
// The result is hierarchical, i.e. each server is returned in one element, and the element contains all its discovery URLs.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

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

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

            // Obtain collection of application elements
            UADiscoveryElementCollection discoveryElementCollection;
            try
            {
                discoveryElementCollection = client.DiscoverGlobalServers(
                    "opc.tcp://opcua.demo-this.com:58810/GlobalDiscoveryServer", 
                    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);
                Console.WriteLine("Application URI string: {0}", discoveryElement.ApplicationUriString);
                Console.WriteLine("Product URI string: {0}", discoveryElement.ProductUriString);
            }
        }
    }
}
# This example shows how to obtain information about OPC UA servers from the Global Discovery Server (GDS).
# The result is hierarchical, i.e. each server is returned in one element, and the element contains all its discovery
# URLs.
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
# OPC client and subscriber examples in Python on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-Python .
# 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.DiscoverGlobalServers(client,
        UAEndpointDescriptor('opc.tcp://opcua.demo-this.com:58810/GlobalDiscoveryServer'),
        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('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 from the Global Discovery Server (GDS).
' The result is hierarchical, i.e. each server is returned in one element, and the element contains all its discovery URLs.
'
' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

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

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

            ' Obtain collection of application elements
            Dim discoveryElementCollection As UADiscoveryElementCollection
            Try
                discoveryElementCollection = client.DiscoverGlobalServers( _
                    "opc.tcp://opcua.demo-this.com:58810/GlobalDiscoveryServer",
                    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)
                Console.WriteLine("Application URI string: {0}", discoveryElement.ApplicationUriString)
                Console.WriteLine("Product URI string: {0}", discoveryElement.ProductUriString)
            Next discoveryElement
        End Sub
    End Class
End Namespace
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