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



OpcLabs.EasyOpcUA Assembly > OpcLabs.EasyOpc.UA.ComTypes Namespace > _EasyUAClient Interface : FindLocalApplications Method
Application types to be discovered.
Discovers available OPC-UA applications and returns information about them, using the specified discovery URI strings and filtering by specified application types.
Discovers available OPC-UA applications and returns information about them, using the specified discovery URI strings and filtering by specified application types.

This method uses the discovery services on specified discovery endpoints.

Invokes the FindServers service.

The discovery may be attempted in parallel on the specified endpoints, depending on component settings.

See also in Knowledge Base: Technical note-OPC UA Discovery in QuickOPC.

Syntax
'Declaration
 
<ElementsNotNullAttribute()>
<NotNullAttribute()>
Function FindLocalApplications( _
   ByVal discoveryUriStringArray As Object, _
   ByVal applicationTypes As UAApplicationTypes _
) As UADiscoveryElementCollection
'Usage
 
Dim instance As _EasyUAClient
Dim discoveryUriStringArray As Object
Dim applicationTypes As UAApplicationTypes
Dim value As UADiscoveryElementCollection
 
value = instance.FindLocalApplications(discoveryUriStringArray, applicationTypes)
[ElementsNotNull()]
[NotNull()]
UADiscoveryElementCollection FindLocalApplications( 
   object discoveryUriStringArray,
   UAApplicationTypes applicationTypes
)
[ElementsNotNull()]
[NotNull()]
UADiscoveryElementCollection^ FindLocalApplications( 
   Object^ discoveryUriStringArray,
   UAApplicationTypes applicationTypes
) 

Parameters

discoveryUriStringArray
applicationTypes
Application types to be discovered.

Return Value

Returns a collection of application elements (servers, OpcLabs.EasyOpc.UA.Discovery.UADiscoveryElement).
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

This method uses the discovery services on specified discovery endpoints.

Invokes the FindServers service.

The discovery may be attempted in parallel on the specified endpoints, depending on component settings.

See also in Knowledge Base: Technical note-OPC UA Discovery in QuickOPC.

Example

.NET

COM

COM

// This example shows how to obtain application URLs of all OPC Unified Architecture servers, using specified discovery URI
// strings.
//
// 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
{
    class FindLocalApplications
    {
        public static void Main1()
        {

            string[] discoveryUriStrings =
            {
                "opc.tcp://opcua.demo-this.com:4840/UADiscovery",
                "http://opcua.demo-this.com/UADiscovery/Default.svc",
                "http://opcua.demo-this.com:52601/UADiscovery"
            };

            // Instantiate the client object.
            var client = new EasyUAClient();

            // Obtain collection of application elements.
            UADiscoveryElementCollection discoveryElementCollection;
            try
            {
                discoveryElementCollection = client.FindLocalApplications(discoveryUriStrings, UAApplicationTypes.Server);
            }
            catch (UAException uaException)
            {
                Console.WriteLine($"*** Failure: {uaException.GetBaseException().Message}");
                return;
            }

            // Display results.
            foreach (UADiscoveryElement discoveryElement in discoveryElementCollection)
                Console.WriteLine($"discoveryElementCollection[\"{discoveryElement.DiscoveryUriString}\"].ApplicationUriString: {discoveryElement.ApplicationUriString}");


            // Example output:
            //discoveryElementCollection["http://opcua.demo-this.com:62543/Quickstarts/AlarmConditionServer"].ApplicationUriString: urn:opcua.demo-this.com:Quickstart Alarm Condition Server
            //discoveryElementCollection["opc.tcp://opcua.demo-this.com:62544/Quickstarts/AlarmConditionServer"].ApplicationUriString: urn:opcua.demo-this.com:Quickstart Alarm Condition Server
            //discoveryElementCollection["opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"].ApplicationUriString: urn:opcua.demo-this.com:UA Sample Server
            //discoveryElementCollection["http://opcua.demo-this.com:51211/UA/SampleServer"].ApplicationUriString: urn:opcua.demo-this.com:UA Sample Server
            //discoveryElementCollection["https://opcua.demo-this.com:51212/UA/SampleServer/"].ApplicationUriString: urn:opcua.demo-this.com:UA Sample Server
            //discoveryElementCollection["opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"].ApplicationUriString: urn:Test-PC:UA Sample Server
        }
    }
}
# This example shows how to obtain application URLs of all OPC Unified Architecture servers, using specified discovery URI
# strings.
#
# 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"

$discoveryUriStrings = @(
    "opc.tcp://opcua.demo-this.com:4840/UADiscovery",
    "http://opcua.demo-this.com/UADiscovery/Default.svc",
    "http://opcua.demo-this.com:52601/UADiscovery")

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

# Obtain collection of application elements.
try {
    $discoveryElementCollection = [IEasyUAClientExtension]::FindLocalApplications($client, 
        $discoveryUriStrings, [UAApplicationTypes]::Server)
}
catch [UAException] {
    Write-Host "*** Failure: $($PSItem.Exception.GetBaseException().Message)"
    return
}

# Display results.
foreach ($discoveryElement in $discoveryElementCollection) {
    Write-Host "discoveryElementCollection[`"$($discoveryElement.DiscoveryUriString)`"].ApplicationUriString: $($discoveryElement.ApplicationUriString)"
}


# Example output:
#
#discoveryElementCollection["http://opcua.demo-this.com:62543/Quickstarts/AlarmConditionServer"].ApplicationUriString: urn:opcua.demo-this.com:Quickstart Alarm Condition Server
#discoveryElementCollection["opc.tcp://opcua.demo-this.com:62544/Quickstarts/AlarmConditionServer"].ApplicationUriString: urn:opcua.demo-this.com:Quickstart Alarm Condition Server
#discoveryElementCollection["opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"].ApplicationUriString: urn:opcua.demo-this.com:UA Sample Server
#discoveryElementCollection["http://opcua.demo-this.com:51211/UA/SampleServer"].ApplicationUriString: urn:opcua.demo-this.com:UA Sample Server
#discoveryElementCollection["https://opcua.demo-this.com:51212/UA/SampleServer/"].ApplicationUriString: urn:opcua.demo-this.com:UA Sample Server
#discoveryElementCollection["opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"].ApplicationUriString: urn:Test-PC:UA Sample Server
# This example shows how to obtain application URLs of all OPC Unified Architecture servers, using specified discovery
# URI strings.
#
# 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 *


discoveryUriStrings = [
    'opc.tcp://opcua.demo-this.com:4840/UADiscovery',
    'http://opcua.demo-this.com/UADiscovery/Default.svc',
    'http://opcua.demo-this.com:52601/UADiscovery'
]

# Instantiate the client object.
client = EasyUAClient()

# Obtain collection of application elements.
try:
    discoveryElementCollection = IEasyUAClientExtension.FindLocalApplications(client,
        discoveryUriStrings, UAApplicationTypes.Server)
except UAException as uaException:
    print('*** Failure: ' + uaException.GetBaseException().Message)
    exit()

# Display results.
for discoveryElement in discoveryElementCollection:
    print('DiscoveryElementCollection["', discoveryElement.DiscoveryUriString, '"].ApplicationUriString: ',
          discoveryElement.ApplicationUriString, sep='')
' This example shows how to obtain application URLs of all OPC Unified Architecture servers, using specified discovery URI strings.
'
' 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
    Friend Class FindLocalApplications
        Public Shared Sub Main1()
            Dim discoveryUriStrings() As String =
            { _
                "opc.tcp://opcua.demo-this.com:4840/UADiscovery", _
                "http://opcua.demo-this.com/UADiscovery/Default.svc", _
                "http://opcua.demo-this.com:52601/UADiscovery" _
            }

            ' Instantiate the client object
            Dim client = New EasyUAClient()

            ' Obtain collection of application elements
            Dim discoveryElementCollection As UADiscoveryElementCollection
            Try
                discoveryElementCollection = client.FindLocalApplications(discoveryUriStrings, UAApplicationTypes.Server)
            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("discoveryElementCollection[""{0}""].ApplicationUriString: {1}", _
                    discoveryElement.DiscoveryUriString, discoveryElement.ApplicationUriString)
            Next discoveryElement

            ' Example output:
            'discoveryElementCollection["http://opcua.demo-this.com:62543/Quickstarts/AlarmConditionServer"].ApplicationUriString: urn:opcua.demo-this.com:Quickstart Alarm Condition Server
            'discoveryElementCollection["opc.tcp://opcua.demo-this.com:62544/Quickstarts/AlarmConditionServer"].ApplicationUriString: urn:opcua.demo-this.com:Quickstart Alarm Condition Server
            'discoveryElementCollection["opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"].ApplicationUriString: urn:opcua.demo-this.com:UA Sample Server
            'discoveryElementCollection["http://opcua.demo-this.com:51211/UA/SampleServer"].ApplicationUriString: urn:opcua.demo-this.com:UA Sample Server
            'discoveryElementCollection["https://opcua.demo-this.com:51212/UA/SampleServer/"].ApplicationUriString: urn:opcua.demo-this.com:UA Sample Server
            'discoveryElementCollection["opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"].ApplicationUriString: urn:Test-PC:UA Sample Server
        End Sub
    End Class
End Namespace
// This example shows how to obtain application URLs of all OPC Unified Architecture servers, using specified discovery URI strings.
//
// Find all latest examples here : https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

class procedure FindLocalApplications.Main;
const
  UAApplicationTypes_Server = 1;
var
  Client: OpcLabs_EasyOpcUA_TLB._EasyUAClient;
  Count: Cardinal;
  Element: OleVariant;
  DiscoveryElement: _UADiscoveryElement;
  DiscoveryElementEnumerator: IEnumVariant;
  DiscoveryElements: _UADiscoveryElementCollection;
  DiscoveryUriStrings: OleVariant;
begin
  DiscoveryUriStrings := VarArrayCreate([0, 2], varVariant);
  DiscoveryUriStrings[0] := 'opc.tcp://opcua.demo-this.com:4840/UADiscovery';
  DiscoveryUriStrings[1] := 'http://opcua.demo-this.com/UADiscovery/Default.svc';
  DiscoveryUriStrings[2] := 'http://opcua.demo-this.com:52601/UADiscovery';

  // Instantiate the client object
  Client := CoEasyUAClient.Create;

  // Obtain collection of application elements
  try
    DiscoveryElements := Client.FindLocalApplications(DiscoveryUriStrings, UAApplicationTypes_Server);
  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(
      'DiscoveryElements["',
      DiscoveryElement.DiscoveryUriString,
      '".ApplicationUriString: ',
      DiscoveryElement.ApplicationUriString);
  end;

  VarClear(DiscoveryUriStrings);
end;
REM This example shows how to obtain application URLs of all OPC Unified Architecture servers, using specified discovery URI strings.
REM
REM Find all latest examples here : https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

Public Sub FindLocalApplications_Main_Command_Click()
    OutputText = ""
    
    Dim DiscoveryUriStrings(2)
    DiscoveryUriStrings(0) = "opc.tcp://opcua.demo-this.com:4840/UADiscovery"
    DiscoveryUriStrings(1) = "http://opcua.demo-this.com/UADiscovery/Default.svc"
    DiscoveryUriStrings(2) = "http://opcua.demo-this.com:52601/UADiscovery"

    ' 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.FindLocalApplications(DiscoveryUriStrings, UAApplicationTypes_Server)
    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 & "DiscoveryElementCollection[""" & DiscoveryElement.DiscoveryUriString & """].ApplicationUriString: " & _
            DiscoveryElement.applicationUriString & vbCrLf
    Next
End Sub
// This example shows how to obtain application URLs of all OPC Unified Architecture servers, using specified discovery URI strings.
//
// Find all latest examples here : https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

class procedure FindLocalApplications.Main;
const
  UAApplicationTypes_Server = 1;
var
  Client: OpcLabs_EasyOpcUA_TLB._EasyUAClient;
  Count: Cardinal;
  Element: OleVariant;
  DiscoveryElement: _UADiscoveryElement;
  DiscoveryElementEnumerator: IEnumVariant;
  DiscoveryElements: _UADiscoveryElementCollection;
  DiscoveryUriStrings: OleVariant;
begin
  DiscoveryUriStrings := VarArrayCreate([0, 2], varVariant);
  DiscoveryUriStrings[0] := 'opc.tcp://opcua.demo-this.com:4840/UADiscovery';
  DiscoveryUriStrings[1] := 'http://opcua.demo-this.com/UADiscovery/Default.svc';
  DiscoveryUriStrings[2] := 'http://opcua.demo-this.com:52601/UADiscovery';

  // Instantiate the client object
  Client := CoEasyUAClient.Create;

  // Obtain collection of application elements
  try
    DiscoveryElements := Client.FindLocalApplications(DiscoveryUriStrings, UAApplicationTypes_Server);
  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(
      'DiscoveryElements["',
      DiscoveryElement.DiscoveryUriString,
      '".ApplicationUriString: ',
      DiscoveryElement.ApplicationUriString);
  end;

  VarClear(DiscoveryUriStrings);
end;
REM This example shows how to obtain application URLs of all OPC Unified Architecture servers, using specified discovery URI strings.
REM
REM Find all latest examples here : https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

Public Sub FindLocalApplications_Main_Command_Click()
    OutputText = ""
    
    Dim DiscoveryUriStrings(2)
    DiscoveryUriStrings(0) = "opc.tcp://opcua.demo-this.com:4840/UADiscovery"
    DiscoveryUriStrings(1) = "http://opcua.demo-this.com/UADiscovery/Default.svc"
    DiscoveryUriStrings(2) = "http://opcua.demo-this.com:52601/UADiscovery"

    ' 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.FindLocalApplications(DiscoveryUriStrings, UAApplicationTypes_Server)
    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 & "DiscoveryElementCollection[""" & DiscoveryElement.DiscoveryUriString & """].ApplicationUriString: " & _
            DiscoveryElement.applicationUriString & vbCrLf
    Next
End Sub
Rem This example shows how to obtain application URLs of all OPC Unified Architecture servers, using specified discovery URI strings.
Rem
Rem Find all latest examples here : https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

Option Explicit

Const UAApplicationTypes_Server = 1

Dim discoveryUriStrings(2)
discoveryUriStrings(0) = "opc.tcp://opcua.demo-this.com:4840/UADiscovery"
discoveryUriStrings(1) = "http://opcua.demo-this.com/UADiscovery/Default.svc"
discoveryUriStrings(2) = "http://opcua.demo-this.com:52601/UADiscovery"

' 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.FindLocalApplications(discoveryUriStrings, UAApplicationTypes_Server)
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 "DiscoveryElementCollection[""" & DiscoveryElement.DiscoveryUriString & """].ApplicationUriString: " & _
        DiscoveryElement.ApplicationUriString
Next
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