// Shows how to find all application's registrations in the GDS.
using System;
using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.AddressSpace;
using OpcLabs.EasyOpc.UA.Application;
using OpcLabs.EasyOpc.UA.Application.Extensions;
using OpcLabs.EasyOpc.UA.Discovery;
using OpcLabs.EasyOpc.UA.Extensions;
using OpcLabs.EasyOpc.UA.OperationModel;
namespace UADocExamples.Application._IEasyUAClientApplication
{
class FindGdsRegistrations
{
public static void Main1()
{
// Define which GDS we will work with.
UAEndpointDescriptor gdsEndpointDescriptor =
((UAEndpointDescriptor)"opc.tcp://opcua.demo-this.com:58810/GlobalDiscoveryServer")
.WithUserNameIdentity("appadmin", "demo");
// Obtain the client application service.
var client = new EasyUAClient();
IEasyUAClientApplication clientApplication = client.GetService<IEasyUAClientApplication>();
// Display which application we are about to work with.
Console.WriteLine("Application URI string: {0}",
clientApplication.GetApplicationElement().ApplicationUriString);
// Find all application's registrations in the GDS.
IReadOnlyDictionary<UANodeId, UAApplicationElement> applicationElementDictionary;
try
{
applicationElementDictionary = clientApplication.FindGdsRegistrations(gdsEndpointDescriptor);
}
catch (UAException uaException)
{
Console.WriteLine("*** Failure: {0}", uaException.GetBaseException().Message);
return;
}
// Display results
foreach (KeyValuePair<UANodeId, UAApplicationElement> pair in applicationElementDictionary)
{
Console.WriteLine();
Console.WriteLine("Application ID: {0}", pair.Key);
UAApplicationElement applicationElement = pair.Value;
Console.WriteLine("Application element: {0}", applicationElement);
Console.WriteLine(" Application URI string: {0}", applicationElement.ApplicationUriString);
Console.WriteLine(" Discovery URI strings: {0}", applicationElement.DiscoveryUriStrings);
Console.WriteLine(" Product URI string: {0}", applicationElement.ProductUriString);
}
}
}
}
// Shows how to find all application's registrations in the GDS.
class procedure FindGdsRegistrations.Main;
var
ApplicationElement: _UAApplicationElement;
ApplicationElementDictionary: _UANodeIdUAApplicationElementReadOnlyDictionary;
ApplicationId: _UANodeId;
Count: Cardinal;
Element: OleVariant;
Enumerator: IEnumVARIANT;
Client: _EasyUAClient;
ClientApplication: _EasyUAClientApplication;
GdsEndpointDescriptor: _UAEndpointDescriptor;
begin
// Define which GDS we will work with.
GdsEndpointDescriptor := CoUAEndpointDescriptor.Create;
GdsEndpointDescriptor.UrlString := 'opc.tcp://opcua.demo-this.com:58810/GlobalDiscoveryServer';
GdsEndpointDescriptor.UserIdentity.UserNameTokenInfo.UserName := 'appadmin';
GdsEndpointDescriptor.UserIdentity.UserNameTokenInfo.Password := 'demo';
// Obtain the client application service.
Client := CoEasyUAClient.Create;
ClientApplication := IInterface(Client.GetServiceByName('OpcLabs.EasyOpc.UA.Application.IEasyUAClientApplication, OpcLabs.EasyOpcUA')) as _EasyUAClientApplication;
// Display which application we are about to work with.
WriteLn('Application URI string: ', ClientApplication.GetApplicationElement.ApplicationUriString);
// Find all application's registrations in the GDS.
try
ApplicationElementDictionary := ClientApplication.FindGdsRegistrations(GdsEndpointDescriptor);
except
on E: EOleException do
begin
WriteLn(Format('*** Failure: %s', [E.GetBaseException.Message]));
end;
end;
// Display results
Enumerator := ApplicationElementDictionary.GetEnumerator;
while (Enumerator.Next(1, Element, Count) = S_OK) do
begin
WriteLn;
ApplicationId := IUnknown(Element.Key) as _UANodeId;
WriteLn('Application ID: ', ApplicationId.ToString);
ApplicationElement := IUnknown(Element.Value) as _UAApplicationElement;
WriteLn(' Application URI string: ', ApplicationElement.ApplicationUriString);
WriteLn(' Discovery URI string: ', ApplicationElement.DiscoveryUriString);
WriteLn(' Product URI string: ', ApplicationElement.ProductUriString);
end;
end;
' Shows how to find all application's registrations in the GDS.
Imports Microsoft.Extensions.DependencyInjection
Imports OpcLabs.EasyOpc.UA
Imports OpcLabs.EasyOpc.UA.AddressSpace
Imports OpcLabs.EasyOpc.UA.Application
Imports OpcLabs.EasyOpc.UA.Application.Extensions
Imports OpcLabs.EasyOpc.UA.Discovery
Imports OpcLabs.EasyOpc.UA.Extensions
Imports OpcLabs.EasyOpc.UA.OperationModel
Namespace UADocExamples.Application._IEasyUAClientApplication
Friend Class FindGdsRegistrations
Public Shared Sub Main1()
' Define which GDS we will work with.
Dim gdsEndpointDescriptor As UAEndpointDescriptor =
New UAEndpointDescriptor("opc.tcp://opcua.demo-this.com:58810/GlobalDiscoveryServer") _
.WithUserNameIdentity("appadmin", "demo")
' Obtain the client application service.
Dim client = New EasyUAClient()
Dim clientApplication = client.GetService(Of IEasyUAClientApplication)()
' Display which application we are about to work with.
Console.WriteLine("Application URI string: {0}",
clientApplication.GetApplicationElement().ApplicationUriString)
' Find all application's registrations in the GDS.
Dim applicationElementDictionary As IReadOnlyDictionary(Of UANodeId, UAApplicationElement)
Try
applicationElementDictionary = clientApplication.FindGdsRegistrations(gdsEndpointDescriptor)
Catch uaException As UAException
Console.WriteLine("*** Failure: {0}", uaException.GetBaseException.Message)
Exit Sub
End Try
' Display results
For Each pair In applicationElementDictionary
Console.WriteLine()
Console.WriteLine("Application ID: {0}", pair.Key)
Dim applicationElement = pair.Value
Console.WriteLine("Application element: {0}", applicationElement)
Console.WriteLine(" Application URI string: {0}", applicationElement.ApplicationUriString)
Console.WriteLine(" Discovery URI strings: {0}", applicationElement.DiscoveryUriStrings)
Console.WriteLine(" Product URI string: {0}", applicationElement.ProductUriString)
Next pair
End Sub
End Class
End Namespace