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



View with Navigation Tools
OpcLabs.EasyOpcUA Assembly > OpcLabs.EasyOpc.UA.Gds Namespace > EasyUAGlobalDiscoveryClientCore Class : QueryServers Method
Endpoint descriptor. Identifies the OPC-UA server. The server must be a Global Directory Server (GDS).

Because the OpcLabs.EasyOpc.UA.UAEndpointDescriptor has implicit conversions from System.String and System.Uri, in languages that support implicit conversion operators (such as C# or VB.NET), you can simply use a string (representing the endpoint URL, or a so-called OPC UA endpoint descriptor string), or a System.Uri object, in place of this parameter, and the corresponding endpoint descriptor will be constructed automatically. When the implicit conversion operators are not supported (such as with Python.NET), you can use the OpcLabs.EasyOpc.UA.UAEndpointDescriptor.FromString or OpcLabs.EasyOpc.UA.UAEndpointDescriptor.FromUri static method instead.

Also, because the OpcLabs.EasyOpc.UA.Discovery.UAApplicationElement and OpcLabs.EasyOpc.UA.Discovery.UADiscoveryElement have an implicit conversion to OpcLabs.EasyOpc.UA.UAEndpointDescriptor, in languages that support implicit conversion operators (such as C# or VB.NET), you can simply use a OpcLabs.EasyOpc.UA.Discovery.UAApplicationElement or OpcLabs.EasyOpc.UA.Discovery.UADiscoveryElement (results from OPC UA discovery) in place of this parameter, and the corresponding endpoint descriptor will be constructed automatically. When the implicit conversion operators are not supported (such as with Python.NET), you can convert a (non-null) OpcLabs.EasyOpc.UA.Discovery.UAApplicationElement or OpcLabs.EasyOpc.UA.Discovery.UADiscoveryElement to OpcLabs.EasyOpc.UA.UAEndpointDescriptor using the ToUAEndpointDescriptor or ToUAEndpointDescriptor method instead.

If you are using OPC Wizard (for server development), an implicit conversion from OpcLabs.EasyOpc.UA.EasyUAServerCore can be used in the same way to simply pass the server object in place of this parameter, which will use its OpcLabs.EasyOpc.UA.EasyUAServerCore.EffectiveServerDescriptor property for the connection.

The value of this parameter cannot be null (Nothing in Visual Basic).

Only records with an identifier greater than this number will be returned.
Specify 0 to start with the first record in the database.

Valid values of this parameter are in the range from 0 to 4294967295.

The maximum number of records to return in the response.
0 indicates that there is no limit.

Valid values of this parameter are in the range from 0 to 4294967295.

The ApplicationName of the applications to return.
Supports the syntax used by the LIKE FilterOperator described in Part 4.
Not used if an empty string is specified. The filter is only applied to the default ApplicationName.

The value of this parameter cannot be null (Nothing in Visual Basic).

The ApplicationUri of the servers to return.
Supports the syntax used by the LIKE FilterOperator described in Part 4.
Not used if an empty string is specified.

The value of this parameter cannot be null (Nothing in Visual Basic).

The ProductUri of the servers to return.
Supports the syntax used by the LIKE FilterOperator described in Part 4.
Not used if an empty string is specified.

The value of this parameter cannot be null (Nothing in Visual Basic).

The capabilities supported by the applications returned. If no server capabilities are provided this filter is not used.

The value of this parameter cannot be null (Nothing in Visual Basic).

The last time the counters were reset.
A list of Servers which meet the criteria (OpcLabs.EasyOpc.UA.Discovery.UAServerOnNetwork).

The value of this parameter cannot be null (Nothing in Visual Basic).

The individual elements of the parameter value cannot be null (Nothing in Visual Basic).

(Depreciated) Finds server applications that meet the specified filters.
Syntax
 
'Usage
 
Dim instance As EasyUAGlobalDiscoveryClientCore
Dim gdsEndpointDescriptor As UAEndpointDescriptor
Dim startingRecordId As Long
Dim maximumRecordsToReturn As Long
Dim applicationName As String
Dim applicationUriString As String
Dim productUriString As String
Dim serverCapabilities As IEnumerable(Of String)
Dim lastCounterResetTime As Date
Dim serverOnNetworkArray() As UAServerOnNetwork
 
instance.QueryServers(gdsEndpointDescriptor, startingRecordId, maximumRecordsToReturn, applicationName, applicationUriString, productUriString, serverCapabilities, lastCounterResetTime, serverOnNetworkArray)

Parameters

gdsEndpointDescriptor
Endpoint descriptor. Identifies the OPC-UA server. The server must be a Global Directory Server (GDS).

Because the OpcLabs.EasyOpc.UA.UAEndpointDescriptor has implicit conversions from System.String and System.Uri, in languages that support implicit conversion operators (such as C# or VB.NET), you can simply use a string (representing the endpoint URL, or a so-called OPC UA endpoint descriptor string), or a System.Uri object, in place of this parameter, and the corresponding endpoint descriptor will be constructed automatically. When the implicit conversion operators are not supported (such as with Python.NET), you can use the OpcLabs.EasyOpc.UA.UAEndpointDescriptor.FromString or OpcLabs.EasyOpc.UA.UAEndpointDescriptor.FromUri static method instead.

Also, because the OpcLabs.EasyOpc.UA.Discovery.UAApplicationElement and OpcLabs.EasyOpc.UA.Discovery.UADiscoveryElement have an implicit conversion to OpcLabs.EasyOpc.UA.UAEndpointDescriptor, in languages that support implicit conversion operators (such as C# or VB.NET), you can simply use a OpcLabs.EasyOpc.UA.Discovery.UAApplicationElement or OpcLabs.EasyOpc.UA.Discovery.UADiscoveryElement (results from OPC UA discovery) in place of this parameter, and the corresponding endpoint descriptor will be constructed automatically. When the implicit conversion operators are not supported (such as with Python.NET), you can convert a (non-null) OpcLabs.EasyOpc.UA.Discovery.UAApplicationElement or OpcLabs.EasyOpc.UA.Discovery.UADiscoveryElement to OpcLabs.EasyOpc.UA.UAEndpointDescriptor using the ToUAEndpointDescriptor or ToUAEndpointDescriptor method instead.

If you are using OPC Wizard (for server development), an implicit conversion from OpcLabs.EasyOpc.UA.EasyUAServerCore can be used in the same way to simply pass the server object in place of this parameter, which will use its OpcLabs.EasyOpc.UA.EasyUAServerCore.EffectiveServerDescriptor property for the connection.

The value of this parameter cannot be null (Nothing in Visual Basic).

startingRecordId
Only records with an identifier greater than this number will be returned.
Specify 0 to start with the first record in the database.

Valid values of this parameter are in the range from 0 to 4294967295.

maximumRecordsToReturn
The maximum number of records to return in the response.
0 indicates that there is no limit.

Valid values of this parameter are in the range from 0 to 4294967295.

applicationName
The ApplicationName of the applications to return.
Supports the syntax used by the LIKE FilterOperator described in Part 4.
Not used if an empty string is specified. The filter is only applied to the default ApplicationName.

The value of this parameter cannot be null (Nothing in Visual Basic).

applicationUriString
The ApplicationUri of the servers to return.
Supports the syntax used by the LIKE FilterOperator described in Part 4.
Not used if an empty string is specified.

The value of this parameter cannot be null (Nothing in Visual Basic).

productUriString
The ProductUri of the servers to return.
Supports the syntax used by the LIKE FilterOperator described in Part 4.
Not used if an empty string is specified.

The value of this parameter cannot be null (Nothing in Visual Basic).

serverCapabilities
The capabilities supported by the applications returned. If no server capabilities are provided this filter is not used.

The value of this parameter cannot be null (Nothing in Visual Basic).

lastCounterResetTime
The last time the counters were reset.
serverOnNetworkArray
A list of Servers which meet the criteria (OpcLabs.EasyOpc.UA.Discovery.UAServerOnNetwork).

The value of this parameter cannot be null (Nothing in Visual Basic).

The individual elements of the parameter value cannot be null (Nothing in Visual Basic).

Exceptions
ExceptionDescription

A null reference (Nothing in Visual Basic) is passed to a method that does not accept it as a valid argument.

This is a usage error, i.e. it will never occur (the exception will not be thrown) in a correctly written program. Your code should not catch this exception.

The OPC UA operation has failed. This operation exception in uniformly used to allow common handling of various kinds of errors. The System.Exception.InnerException always contains information about the actual error cause.

This is an operation error that depends on factors external to your program, and thus cannot be always avoided. Your code must handle it appropriately.

Remarks

There are higher-level methods that are easier to use and can be used instead. Have a look e.g. at:

Example
// Shows how to find server applications that meet the specified filters, using the global discovery client.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

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

namespace UADocExamples.Gds._EasyUAGlobalDiscoveryClient
{
    class QueryServers
    {
        public static void Main1()
        {
            // Instantiate the global discovery client object
            var globalDiscoveryClient = new EasyUAGlobalDiscoveryClient();

            // Find all servers registered in the GDS.
            UAServerOnNetwork[] serverOnNetworkArray;
            try
            {
                globalDiscoveryClient.QueryServers(
                    gdsEndpointDescriptor:"opc.tcp://opcua.demo-this.com:58810/GlobalDiscoveryServer",
                    startingRecordId:0,
                    maximumRecordsToReturn:0,
                    applicationName:"",
                    applicationUriString:"",
                    productUriString:"",
                    serverCapabilities:new string[0],
                    lastCounterResetTime:out _,
                    serverOnNetworkArray:out serverOnNetworkArray);
            }
            catch (UAException uaException)
            {
                Console.WriteLine("*** Failure: {0}", uaException.GetBaseException().Message);
                return;
            }

            // Display results
            foreach (UAServerOnNetwork serverOnNetwork in serverOnNetworkArray)
            {
                Console.WriteLine();
                Console.WriteLine("Server name: {0}", serverOnNetwork.ServerName);
                Console.WriteLine("Discovery URL string: {0}", serverOnNetwork.DiscoveryUrlString);
                Console.WriteLine("Server capabilities: {0}", serverOnNetwork.ServerCapabilities);
            }
        }
    }
}
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