.NET Based OPC UA Client/Server SDK  3.0.10.493
Application Instance

Overview

The ApplicationInstance manages the application configuration and is associated with one or more Session instances. Each process has a default ApplicationInstance which can be accessed with the ‘Default’ property.

An ApplicationInstance must be started before it can be used by calling the Start method. This executes the activity shown in the following figure:

l3baselibappinstanceoverview.png

The ParseCommandLine action validates the command line arguments. The command line syntax requires command keywords proceeded by a forward slash and followed by an optional parameter separated by a colon. For example:

/silent /configFile:"C:\My Config.xml"

Double quotes must be used to enclose parameters with whitespaces.

The LoadConfiguration action loads the Application configuration file from a file or a resource. It looks in the following locations for a configuration file:

  1. The value of the /configFile command line parameter;
  2. The value of the ConfigurationFilePath property;
  3. The UaApplicationConfiguration configuration section in the app.config file;
  4. An embedded resource in the entry Assembly with a file name ‘ApplicationSettings.xml’.

app.config is loaded by the .NET application. If the SDK is used as an assembly by another application, the configuration should be set in code or by an external config file.

If no configuration file is found, a default configuration is generated automatically.

The schema used by the configuration file is the SecuredApplication schema defined in Part 6 with extensions that are described at Configuration Schema.

The ProcessCommandLine action does any special processing based on the command line arguments. If no further processing is required, then the Start method exits.

The ApplicationInstance class supports the following command line parameters:

ParameterDescription
/serviceStarts the application as a service (/service [/silent] [/configFile:<filepath>]).
It is necessary to set the parameter InstallAsService and ServiceName in the config file and install the application using /install (see below) first.
/installInstalls the application (/install [/silent] [/configFile:<filepath>]).
/uninstallUninstalls the application (/uninstall [/silent] [/configFile:<filepath>]).
/silentPerforms operations without prompting user to confirm or displaying errors.
/configFileThe configuration file to use with the application.

Application Developers can add support for additional arguments by creating a subclass of ApplicationInstance.

The CheckConfiguration action verifies that the configuration is correct and assigns suitable default values to any missing parameters. It will only generate an error if it cannot recover. This activity will generate a new Application Certificate if the AutoCreateCertificate property is set to TRUE.

The CheckConfiguration action will also update the ApplicationUri if it has “localhost” specified as the domain by replacing the “localhost” with the default DNS name of the current computer. This provides an easy way to generate unique ApplicationUris for each machine containing an instance of the application. It will do the same with any BaseAddresses that have “localhost” as their domain.

The RunAsService action starts the application as a Windows Service. This action will run if the application is launched by a non-interactive user. It passes control to the Service Control Manager (SCM) which will then complete the activity from a different thread. The Start method exits normally.

The StartServer action opens any sockets required to receive requests from Clients. It is only executed if a valid Server object was passed to the method.

The final step in the action invokes the Run callback if one was provided to the Start method. If no callback was provided, the activity completes and the method exits.

Application Developers can create subclasses of the ApplicationInstance object and customize the behavior of any of the activities.