The samples in this repository are hosted by the OPC Foundation to keep the sample code available for the community.
However, to avoid internal competition with OPC members that offer commercial SDKs, the OPC Foundation limits its own resources for maintenance and support to a minimum.
Contributions of the community to improve and maintain the samples and to help with issues to keep this repository alive are very welcome.
Please follow the steps outlined here to start contributing.
Sample Servers and Clients, including all required controls, targeting .NET 10, .NET 8 and .NET Framework 4.8.
Integrates the offical OPC UA NuGet package containing the OPC UA reference implementation targeting .NET Standard.
.Net Standard allows you develop apps that run on all common platforms available today, including Linux, macOS and Windows, without requiring platform-specific modifications. Furthermore, cloud applications and services (such as ASP.Net, Azure Websites, Azure Webjobs and Azure Service Fabric) are also supported. The Windows Forms samples in this repository run on Windows only; the console samples are cross platform.
For more information and license terms, see here.
- Sample Servers and Clients, including all required controls, for .NET 10, .NET 8 and .NET Framework 4.8.
- Sessions (including UI support in the samples).
- Subscriptions (including UI support in the samples).
- OPC UA Aggregation Server.
- OPC UA Global Discovery Client and Global Discovery Server.
- OPC UA Local Discovery Server.
- OPC UA Quickstart Samples.
- OPC Classic adapter for OPC UA, OPC UA Xamarin Client and the Mono console samples were removed in 12/2024.
This repository holds the Windows Forms clients and servers and the quickstart
workshop samples. The samples for PubSub (Part 14), Device Integration (Part
100), Robotics, Vision, AI Model Management, ISA-95, OpenUSD, WoT Connectivity
and the minimal / Native-AOT servers live next to the stack itself, in the
samples
folder of the UA-.NETStandard
repository.
Use this table to quickly find the project that suits your needs. If you already have an external OPC UA server (e.g. KepServerEX, Prosys, or another vendor server), you only need to run a Client sample and point it at your server's endpoint URL.
| Project | Type | Description |
|---|---|---|
| ReferenceServer | Server | The OPC UA Reference Server. Implements a rich address space designed for OPC UA Compliance Test Tool (UACTT) testing. Use this as a standards-compliant server to test clients against. |
| ReferenceClient | Client | A Windows Forms OPC UA client that can connect to any OPC UA server. Use this if you want to browse, read, write, subscribe to nodes, or test client connectivity against an external server such as KepServerEX. Also exports the address space of the connected server to a NodeSet2 file, and waits for a server which connects out to it behind a firewall. See the sample README. |
| UA Sample Server (.NET 4.6) | Server | A feature-rich OPC UA sample server with Windows Forms UI for .NET Framework 4.6. Demonstrates sessions, subscriptions and a sample address space. |
| UA Sample Client (.NET 4.6) | Client | A feature-rich OPC UA sample client with Windows Forms UI for .NET Framework 4.6. Can connect to any OPC UA server. Use this to explore and interact with an existing server. Its subscription dialogs cover the monitored item services including SetTriggering, and the session tree exports the address space to a NodeSet2 file. See the sample README. |
| GlobalDiscoveryServer | Server | OPC UA Global Discovery Server (GDS) for .NET 4.6 with SQL Server as database. Manages application registration and certificate issuance across a UA network. |
| NetCoreGlobalDiscoveryServer | Server | Cross-platform console GDS server using a JSON-based database. Use for testing GDS workflows without SQL Server. |
| GlobalDiscoveryClient | Client | Windows Forms GDS client. Use this to register applications, request CA-signed certificates, and manage trust lists via a running GDS server. |
| ConsoleLds | Server | Cross-platform console Local Discovery Server built on Opc.Ua.Lds.Server. Servers register with it and clients call FindServers / FindServersOnNetwork against it. |
| Opc.Ua.Samples.Hosting | Library | The bootstrap every sample shares: dependency injection, the .NET Generic Host and file based logging. Read this first if you want to know how a sample starts up. |
| Opc.Ua.Samples.Client | Library | The half of a sample client which talks OPC UA and knows nothing about the window: the base class of the client models, the session helpers they share and the pumps which turn subscription callbacks into events. Read this to see how a Workshop client is put together. |
| Opc.Ua.Samples.WinForms | Library | The dependency injection plumbing of the Windows Forms samples: the factory a form or a control creates the dialogs it opens with, so a dialog takes what it needs through its constructor instead of being handed it by whoever opened it. |
These paired client/server samples each demonstrate a specific OPC UA feature set. If you have an external server that supports the relevant feature, you can run only the Client against it.
| Project | Type | Description |
|---|---|---|
| Aggregation Server | Server | Aggregates multiple OPC UA servers into a single namespace. Browse aggregated servers via the Aggregation Client or any OPC UA client. |
| Aggregation Client | Client | Connects to an Aggregation Server and browses its aggregated address space. |
| ConsoleAggregationServer | Server | Cross-platform console version of the Aggregation Server. |
| AlarmCondition Server | Server | Demonstrates OPC UA Part 9 Alarms & Conditions: areas and sources which route events, latching trip alarms, re-alarming, silencing, the two suppression patterns, filtered retain and alarm metrics. See the sample README. |
| AlarmCondition Client | Client | Subscribes to alarm events, shows the Part 9 state of each condition, drops a condition from the list as it stops asking for attention or leaves the filter, and calls every condition Method through the typed AlarmClient. |
| AliasNames Server | Server | Demonstrates OPC UA Part 17 alias names: a searchable index of the tag names people use, laid over an address space organized by structure, served both on the standard well-known categories and on an application-defined category tree. See the sample README. |
| AliasNames Client | Client | Searches a Part 17 category by wildcard, resolves a tag name to a NodeId and back, and adds or deletes aliases at runtime. |
| Boiler Server | Server | Simulates a boiler process with UA object instances. Demonstrates object types, methods and data variables. |
| Boiler Client | Client | Connects to the Boiler Server to read boiler state and invoke control methods. |
| DataAccess Server | Server | Demonstrates the OPC UA DataAccess profile with analog items, discrete items and array variables. |
| DataAccess Client | Client | Reads and writes DataAccess items (analog/discrete) on a DataAccess server. |
| DataTypes Server | Server | Demonstrates how to define and expose custom structured data types in OPC UA. |
| DataTypes Client | Client | Reads custom structured data types from a DataTypes server, and generates their XSD, OPC Binary and JSON Schema documents at run time, including for the types it first meets on the wire. |
| FileTransfer Server | Server | Publishes a directory of the host as an OPC UA file system (Part 5 Annex C / Part 20 FileType and FileDirectoryType), using the file system node manager of the SDK. See the sample overview. |
| FileTransfer Client | Client | Browses the file system of a server and uploads, downloads, creates and deletes files and directories. Works against any server which offers Server/FileSystem. |
| HistoricalAccess Server | Server | Serves a file based archive of past values through the historian provider model of the SDK (raw, modified, at-time, processed, annotations, atomic updates and deletes, with the displaced values audited), next to live variables whose history the in-memory engine of the SDK captures - one of them structured. See the sample overview. |
| HistoricalAccess Client | Client | Reads, aggregates, annotates and rewrites the history of a variable on any server, through session.Historian(), and watches the audit trail of the history updates. |
| HistoricalEvents Server | Server | Serves an archive of well test reports as event history through an IHistorianEventProvider, including writing, replacing and deleting events with the displaced reports audited. |
| HistoricalEvents Client | Client | Queries, displays, rewrites and deletes historical events on a HistoricalEvents server, through session.Historian(). |
| Methods Server | Server | Exposes UA methods with various input/output arguments to demonstrate method invocation. |
| Methods Client | Client | Discovers and calls UA methods on a Methods server. |
| NodeManagement Server | Server | Demonstrates the OPC UA Part 4 §5.8 NodeManagement service set: a node manager opts in with one property, and decides where clients may build, what they may not delete, and what a server-assigned NodeId looks like. See the sample README. |
| NodeManagement Client | Client | Creates and deletes nodes and references in the running server, and follows the model change events which report what other clients did. |
| PerfTest Server | Server | Performance test server that exposes a large number of monitored variables for throughput benchmarking. |
| PerfTest Client | Client | Performance test client that subscribes to many variables and measures data-change throughput. Also shows the unbounded monitored item mode of the V2 subscription engine: one logical subscription spread over as many server-side partitions as the per-subscription cap needs. See the sample README. |
| RoleManagement Server | Server | Demonstrates OPC UA Part 18 role-based security: identities earn Roles, RolePermissions on nodes decide what each Role may browse, read, write or call, and the RoleSet lets a SecurityAdmin change that at runtime. See the sample README. |
| RoleManagement Client | Client | Connects as different accounts to see how the address space and the permissions change, and manages the RoleSet of the server. |
| RuntimeNodeSets Server | Server | The two ways a NodeSet2 document reaches a running server: hosted as its own node manager with no source generation at all, added, reloaded and removed through INodeManagerLifecycle while the server runs - and overlaid onto a generated model with INodeManagerBuilder.Import, filling the placeholder slots the model design left. See the sample README. |
| RuntimeNodeSets Client | Client | Loads, reloads and removes the hosted model of its server over OPC UA, watches what each of the three reload modes does to a MonitoredItem, and browses the overlaid model to show which of its nodes no type declares. |
| SimpleEvents Server | Server | Generates simple OPC UA events to demonstrate event subscriptions. |
| SimpleEvents Client | Client | Subscribes to and displays simple events from an events server. |
| StateMachines Server | Server | Demonstrates OPC UA Part 16 state machines: one declared with the fluent StateMachineBuilder (states, transitions, causes, guards, timed transitions and a sub state machine below one of its states) and the standard ProgramStateMachineType with behaviour attached to it. |
| StateMachines Client | Client | Drives both state machines of a StateMachines server, reads the states and transitions each of them declares, and streams the transitions of a machine and of its sub state machine as they happen. |
| UserAuthentication Server | Server | Demonstrates OPC UA user authentication with username/password and certificate-based identity tokens. |
| UserAuthentication Client | Client | Connects using different user identity tokens (anonymous, username, certificate) to a UserAuthentication server. |
| Views Server | Server | Demonstrates OPC UA Views — subsets of the address space exposed as named views. |
| Views Client | Client | Browses and reads nodes through Views defined on a Views server. |
| Empty Server | Server | A minimal server template with no custom nodes. Use as a starting point to build your own OPC UA server. |
| Empty Client | Client | A minimal client template. Use as a starting point to build your own OPC UA client. |
Quick tip: If you already have an OPC UA server running (e.g. KepServerEX, Prosys OPC UA Server, or another vendor product), you do not need to start any server sample. Simply run the ReferenceClient or UA Sample Client and connect to your server's endpoint URL (e.g.
opc.tcp://myserver:49320).
All the tools you need for .Net Standard come with the .Net Core tools. See here for what you need.
The samples build against the preview packages of the OPC UA .NET Standard stack, which the nuget-publish workflow publishes to the GitHub Packages feed of the OPC Foundation organization on every master build. The feed is declared in Nuget.Config:
https://nuget.pkg.github.com/OPCFoundation/index.json
GitHub Packages requires authentication even for public feeds. To restore locally, create a
personal access token with the read:packages scope and store
it for the feed once (in your user-level NuGet configuration, not in the repository):
dotnet nuget update source opcfoundation-github --username <your-github-username> --password <your-token> --store-password-in-clear-text
Alternatively add the credentials to %AppData%\NuGet\NuGet.Config (Windows) or
~/.nuget/NuGet/NuGet.Config (Linux/macOS) with the same opcfoundation-github key.
The Azure DevOps pipelines authenticate through the Github-Feed NuGet
service connection of the Azure DevOps project, which the NuGetAuthenticate task hands to
the restore steps. The service connection is of type NuGet with basic authentication: the
feed URL must match the one in Nuget.Config exactly, the username can be
anything, and the password is a token with the read:packages scope as above.
The version the samples currently build against is pinned in a single place, the
OpcUaNetStandardVersion property in targets.props.
Since Nuget version 1.4.363.107 there is support for symbol snupkg packages on Nuget.Org and github source link.
- See devblog for more information on how to setup the debug symbol server.
- Support for Sourcelink for integrated source code debugging experience.
All required application certificates for OPC UA are created at the first start of each application in a directory or OS-level certificate store and remain in use until deleted from the store.
By default the self signed certificates are stored in a X509Store called CurrentUser\UA_MachineDefault. The certificates can be viewed or deleted with the Windows Certificate Management Console (certmgr.msc). The trusted, issuer and rejected stores remain in a folder called OPC Foundation\CertificateStores with a root folder which is specified by the SpecialFolder variable %CommonApplicationData%, usually the hidden folder C:\ProgramData.
Note: Since the sample applications in the UA-.Net repository use the same storage and application names as UA-.NetStandard, but create only certificates with hostname localhost, it is recommended to delete all existing certificates in MachineDefault to recreate proper certificates for all sample applications when moving to the UA-.NetStandard repository.
The self signed certificates are stored in a folder called OPC Foundation/CertificateStores/MachineDefault with a root folder which is specified by the SpecialFolder variable %LocalApplicationData% or in a X509Store called CurrentUser\My, depending on the configuration. For best cross platform support the personal store CurrentUser\My was chosen to support all platforms with the same configuration. Some platforms, like macOS, do not support arbitrary certificate stores.
The trusted, issuer and rejected stores remain in a shared folder called OPC Foundation\CertificateStores with a root folder specified by the SpecialFolder variable %LocalApplicationData%. Depending on the target platform, this folder maps to a hidden locations under the user home directory.
By default all sample applications are configured to register with a Local Discovery Server (LDS). A reference implementation of a LDS for Windows can be downloaded here. To setup trust with the LDS the certificates need to be exchanged or registration will fail.
- Open the
UA Samples.slnxsolution file using Visual Studio 2022 or later. - Choose a project in the Solution Explorer and set it with a right click as
Startup Project. - Hit
F5to build and execute the sample.
The older UA Sample Applications.sln, UA Quickstart Applications.sln,
UA Aggregation.sln and UA Global Discovery Server.sln files each open a
subset of the same projects and are kept for convenience.
The console samples of this repository are the ConsoleAggregationServer, the NetCoreGlobalDiscoveryServer and the ConsoleLds. The Windows Forms samples need Windows.
Please follow instructions in this article to setup the dotnet command line environment for your platform. The .NET 10 SDK is required to build every target framework of the samples.
- Once the
dotnetcommand is available, navigate to the root folder in your local copy of the repository and executedotnet restore "UA Samples.slnx". This command calls into NuGet to restore the tree of dependencies.
- Open a command prompt.
- Navigate to the root folder of your local copy of the repository.
- To run the console aggregation server type:
dotnet run --project "Workshop/Aggregation/ConsoleAggregationServer/ConsoleAggregationServer.csproj"- The server is now running and waiting for connections.
- Start one of the Windows Forms clients, for example the ReferenceClient or the UA Sample Client, and point it at the endpoint the server printed.
- On first connection, or after certificates were renewed, the server may have refused the client certificate. Check the server and client folder %LocalApplicationData%/OPC Foundation/CertificateStores/RejectedCertificates for rejected certificates. To approve a certificate copy it to the %LocalApplicationData%/OPC Foundation/CertificateStores/UA Applications folder.
- Retry step 1 to connect using a secure connection.
- Please refer to the OPC Foundation UA .Net Standard Library Aggregation Client and Server for a detailed description how to run the aggregation client and server.
We strongly encourage community participation and contribution to this project. First, please fork the repository and commit your changes there. Once happy with your changes you can generate a 'pull request'.
You must agree to the contributor license agreement before we can accept your changes. The CLA and "I AGREE" button is automatically displayed when you perform the pull request. You can preview CLA here.