private static async Task RunClient(string address)
{
var clientApp = new ApplicationInstance
{
ApplicationName = "OPC UA StackOverflow Example Client",
ApplicationType = ApplicationType.Client,
ConfigSectionName = "Opc.Client"
};
// load the application configuration.
var clientConfig = await clientApp.LoadApplicationConfiguration(true);
var haveClientAppCertificate = await clientApp.CheckApplicationInstanceCertificate(true, 0);
if (!haveClientAppCertificate)
{
throw new Exception("Application instance certificate invalid!");
}
var endpointConfiguration = EndpointConfiguration.Create(clientConfig);
var selectedEndpoint = CoreClientUtils.SelectEndpoint(address, true, 15000);
var endpoint = new ConfiguredEndpoint(null, selectedEndpoint, endpointConfiguration);
using (var session = await Session.Create(clientConfig, endpoint, false, clientConfig.ApplicationName, 60000, new UserIdentity(new AnonymousIdentityToken()), null))
{
Console.WriteLine("Client connected");
var rootFolders = await session.BrowseAsync(ObjectIds.ObjectsFolder);
Console.WriteLine("Received root folders");
var childFolders = await Task.WhenAll(
from root in rootFolders
select session.BrowseAsync(ExpandedNodeId.ToNodeId(root.NodeId, session.NamespaceUris)));
foreach (var childFolder in childFolders.SelectMany(x => x).OrderBy(c => c.BrowseName.Name))
{
Console.WriteLine(childFolder.BrowseName.Name);
}
Console.WriteLine("Client disconnecting");
session.Close();
Console.WriteLine("Client disconnected");
}
Console.WriteLine("Client disposed");
}