QuickOPC User's Guide and Reference
QueryServers Method (IEasyUAGlobalDiscoveryClient)
Example 



View with Navigation Tools
OpcLabs.EasyOpcUA Assembly > OpcLabs.EasyOpc.UA.Gds Namespace > IEasyUAGlobalDiscoveryClient Interface : QueryServers Method
Endpoint descriptor. Identifies the OPC-UA server. The server must be a Global Directory Server (GDS).
Only records with an identifier greater than this number will be returned.
Specify 0 to start with the first record in the database.
The maximum number of records to return in the response.
0 indicates that there is no limit.
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 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 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 capabilities supported by the applications returned. If no server capabilities are provided this filter is not used.
The last time the counters were reset.
A list of Servers which meet the criteria (OpcLabs.EasyOpc.UA.Discovery.UAServerOnNetwork).
(Depreciated) Finds server applications that meet the specified filters.
Syntax
 
'Usage
 
Dim instance As IEasyUAGlobalDiscoveryClient
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).
startingRecordId
Only records with an identifier greater than this number will be returned.
Specify 0 to start with the first record in the database.
maximumRecordsToReturn
The maximum number of records to return in the response.
0 indicates that there is no limit.
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.
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.
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.
serverCapabilities
The capabilities supported by the applications returned. If no server capabilities are provided this filter is not used.
lastCounterResetTime
The last time the counters were reset.
serverOnNetworkArray
A list of Servers which meet the criteria (OpcLabs.EasyOpc.UA.Discovery.UAServerOnNetwork).
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

.NET

COM

// Shows how to find server applications that meet the specified filters, using the global discovery client.

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);
            }
        }
    }
}
// Shows how to find server applications that meet the specified filters, using the global discovery client.

class procedure QueryServers.Main;
var
  ApplicationName: WideString;
  ApplicationUriString: WideString;
  GlobalDiscoveryClient: OpcLabs_EasyOpcUA_TLB._EasyUAGlobalDiscoveryClient;
  GdsEndpointDescriptor: _UAEndpointDescriptor;
  I: integer;
  LastCounterResetTime: TDateTime;
  MaximumRecordsToReturn: Integer;
  ProductUriString: WideString;
  ServerCapabilities: array of string;
  ServerOnNetwork: _UAServerOnNetwork;
  ServerOnNetworkArray: OleVariant;
  StartingRecordId: Integer;
begin
  // Define which GDS we will work with.
  GdsEndpointDescriptor := CoUAEndpointDescriptor.Create;
  GdsEndpointDescriptor.UrlString := 'opc.tcp://opcua.demo-this.com:58810/GlobalDiscoveryServer';

  // Instantiate the global discovery client object
  GlobalDiscoveryClient := CoEasyUAGlobalDiscoveryClient.Create;

  // Find all servers registered in the GDS.
  StartingRecordId := 0;
  MaximumRecordsToReturn := 0;
  ApplicationName := '';
  ApplicationUriString := '';
  ProductUriString := '';
  try
    GlobalDiscoveryClient.QueryServers(
      GdsEndpointDescriptor,
      StartingRecordId,
      MaximumRecordsToReturn,
      ApplicationName,
      ApplicationUriString,
      ProductUriString,
      ServerCapabilities,
      LastCounterResetTime,
      ServerOnNetworkArray);
  except
    on E: EOleException do
    begin
      WriteLn(Format('*** Failure: %s', [E.GetBaseException.Message]));
    end;
  end;

  // Display results
  for I := VarArrayLowBound(ServerOnNetworkArray,1) to VarArrayHighBound(ServerOnNetworkArray,1) do
  begin
    ServerOnNetwork := IUnknown(ServerOnNetworkArray[I]) as _UAServerOnNetwork;
    WriteLn;
    WriteLn('Server name: ', ServerOnNetwork.ServerName);
    WriteLn('Discovery URL string: ', ServerOnNetwork.DiscoveryUrlString);
    WriteLn('Server capabilities: ', ServerOnNetwork.ServerCapabilities.ToString);
  end;

end;
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