Skip to content

Add MinimalClient - lightweight OPC UA console client with fluent API - #4006

Merged
marcschier merged 29 commits into
masterfrom
copilot/add-minimal-console-client-example
Jul 17, 2026
Merged

Add MinimalClient - lightweight OPC UA console client with fluent API#4006
marcschier merged 29 commits into
masterfrom
copilot/add-minimal-console-client-example

Conversation

Copilot AI commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Description

Adds MinimalClient, a compact console OPC UA application demonstrating the unified dependency-injection surface, secure endpoint discovery, managed sessions, fluent V2 subscriptions, and Alarms & Conditions support.

Changes

  • Adds ConfigureApplication(options => ...) to build and validate one shared ApplicationConfiguration for combined client/server hosts.
  • Extends OpcUaClientOptions so the existing AddClient(options => ...) callback accepts application identity, PKI, and certificate-validation settings like AddServer(...).
  • Composes root ConfigureApplication(...) values with client defaults in either registration order; shared values take precedence and client values fill gaps.
  • Keeps server samples on their established AddServer(...) configuration pattern.
  • Adds MinimalClient as a .NET 10 Native AOT console application using top-level statements and HostApplicationBuilder.
  • Discovers a SignAndEncrypt / Basic256Sha256 endpoint by default; --insecure and --auto-accept are explicit opt-ins with warnings.
  • Demonstrates fluent AddSubscription(...), TryAddMonitoredItem(...), and AlarmClientFactory usage.
  • Adds targeted configuration, client, and combined client/server tests.

Example

builder.Services
    .AddOpcUa()
    .AddClient(options =>
    {
        options.ApplicationName = "MinimalClient";
        options.ApplicationUri = "urn:localhost:OPCFoundation:MinimalClient";
        options.ProductUri = "uri:opcfoundation.org:MinimalClient";
        options.Session = new ManagedSessionOptions
        {
            SessionName = "MinimalClient",
            SessionTimeout = TimeSpan.FromSeconds(60)
        };
    })
    .AddDiscoveryAndConnect(options =>
    {
        options.DiscoveryUrl = discoveryUrl;
        options.SecurityMode = MessageSecurityMode.SignAndEncrypt;
        options.SecurityPolicyUri = SecurityPolicies.Basic256Sha256;
    })
    .AddSubscriptions()
    .AddAlarms();

Related Issues

If there is no issue yet, open one and link it here.

Checklist

  • I have signed the CLA and read the CONTRIBUTING doc.
  • I have added tests that prove my fix is effective or that my feature works and increased code coverage.
  • I have added all necessary documentation.
  • I have verified that my changes do not introduce new build or analyzer warnings.
  • I ran all tests locally using the UA.slnx solution against at least .NET Framework and .NET 10.
  • I fixed all failing and flaky tests in the CI pipelines and all CodeQL warnings.
  • I have addressed all PR feedback received.

@CLAassistant

CLAassistant commented Jul 15, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 3 committers have signed the CLA.

✅ romanett
✅ marcschier
❌ Copilot
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI linked an issue Jul 15, 2026 that may be closed by this pull request
5 tasks
Copilot AI changed the title [WIP] Add minimal OPC UA console client example Add MinimalClient - lightweight OPC UA console client with fluent API Jul 15, 2026
Copilot AI requested a review from romanett July 15, 2026 11:42
@romanett

Copy link
Copy Markdown
Contributor

Comment thread Applications/MinimalClient/Program.cs Outdated

Copilot AI commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

@copilot use the DI container described here: https://github.com/OPCFoundation/UA-.NETStandard/blob/master/Docs/DependencyInjection.md

✅ Implemented. MinimalClient now uses the DI container as described in the DependencyInjection.md documentation:

  • HostApplicationBuilder for DI setup
  • Fluent .AddOpcUa(), .AddClient(), and .AddAlarms() API
  • IManagedSessionFactory resolved from DI container
  • Configuration options bound via OpcUaClientOptions

See the updated Program.cs for the pattern.

Copilot AI requested a review from romanett July 15, 2026 13:07
@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.94737% with 42 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.48%. Comparing base (007cfaf) to head (9dfb6e6).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
...iguration/OpcUaApplicationConfigurationProvider.cs 83.92% 12 Missing and 6 partials ⚠️
.../Opc.Ua.Server/Hosting/OpcUaServerHostedService.cs 82.05% 7 Missing and 7 partials ⚠️
...ting/OpcUaServerApplicationConfigurationFeature.cs 84.37% 0 Missing and 10 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4006      +/-   ##
==========================================
- Coverage   73.72%   73.48%   -0.24%     
==========================================
  Files        1340     1345       +5     
  Lines      179309   179707     +398     
  Branches    31541    31615      +74     
==========================================
- Hits       132188   132051     -137     
- Misses      36385    36968     +583     
+ Partials    10736    10688      -48     
Files with missing lines Coverage Δ
...c/Opc.Ua.Client/Discovery/OpcUaDiscoveryService.cs 100.00% <100.00%> (+52.38%) ⬆️
...uent/OpcUaClientApplicationConfigurationFeature.cs 100.00% <100.00%> (ø)
...c.Ua.Client/Fluent/OpcUaClientBuilderExtensions.cs 81.63% <100.00%> (+1.67%) ⬆️
src/Opc.Ua.Client/Fluent/OpcUaClientOptions.cs 100.00% <100.00%> (ø)
...a.Configuration/ApplicationConfigurationBuilder.cs 95.58% <100.00%> (+0.17%) ⬆️
...rc/Opc.Ua.Configuration/OpcUaApplicationOptions.cs 100.00% <100.00%> (ø)
...n/OpcUaConfigurationServiceCollectionExtensions.cs 93.33% <100.00%> (+33.33%) ⬆️
....Ua.Server/Hosting/OpcUaServerBuilderExtensions.cs 70.33% <100.00%> (+0.15%) ⬆️
...ting/OpcUaServerApplicationConfigurationFeature.cs 84.37% <84.37%> (ø)
.../Opc.Ua.Server/Hosting/OpcUaServerHostedService.cs 75.31% <82.05%> (+19.80%) ⬆️
... and 1 more

... and 55 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@marcschier
marcschier requested a review from Copilot July 15, 2026 15:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot couldn't run its full agentic review because no GitHub Actions runner was available. Make sure your repository has a runner available to run Copilot's review, or add a copilot-setup-steps.yml file specifying one with the runs-on attribute. See the docs for more details.

Adds a new “MinimalClient” console application to the solution to demonstrate a lightweight OPC UA client built with DI and the managed-session fluent APIs.

Changes:

  • Added Applications/MinimalClient project (net10.0, Native AOT) with a simple browse + read flow.
  • Wired the new project into UA.slnx and added a missing Microsoft.Extensions.DependencyInjection package version.
  • Added README documentation for running and understanding the sample.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
UA.slnx Adds the new MinimalClient project to the solution.
Directory.Packages.props Adds a package version entry for Microsoft.Extensions.DependencyInjection.
Applications/MinimalClient/README.md Documents the MinimalClient purpose, features, and usage.
Applications/MinimalClient/Properties/AssemblyInfo.cs Adds assembly metadata for the new project.
Applications/MinimalClient/Program.cs Implements the minimal console client (DI setup + connect + browse + read).
Applications/MinimalClient/MinimalClient.csproj Defines the new net10.0 console app project with AOT enabled and references.

Comment thread Applications/MinimalClient/Program.cs Outdated
Comment thread Applications/MinimalClient/Program.cs Outdated
Comment thread Applications/MinimalClient/Program.cs Outdated
Comment thread Applications/MinimalClient/Program.cs Outdated
Comment thread Applications/MinimalClient/Program.cs Outdated
Comment thread samples/MinimalClient/Program.cs
Comment thread Applications/MinimalClient/README.md Outdated
Comment thread Applications/MinimalClient/Program.cs Outdated
Comment thread Applications/MinimalClient/Program.cs Outdated
@marcschier
marcschier marked this pull request as ready for review July 15, 2026 20:17
@marcschier marcschier added the ready Ready to merge once CI Passes label Jul 16, 2026
# Conflicts:
#	UA.slnx
#	src/Opc.Ua.Client/Fluent/OpcUaClientApplicationConfigurationFeature.cs
#	src/Opc.Ua.Configuration/IOpcUaApplicationConfigurationFeature.cs
#	src/Opc.Ua.Configuration/IOpcUaApplicationConfigurationProvider.cs
#	src/Opc.Ua.Configuration/OpcUaApplicationConfigurationProvider.cs
#	src/Opc.Ua.Configuration/OpcUaApplicationOptions.cs
#	src/Opc.Ua.Server/Hosting/OpcUaServerApplicationConfigurationFeature.cs
#	tests/Opc.Ua.Configuration.Tests/OpcUaApplicationConfigurationProviderTests.cs
Comment thread samples/RedundantServer/Program.cs
@marcschier
marcschier merged commit b76022d into master Jul 17, 2026
208 of 210 checks passed
@marcschier
marcschier deleted the copilot/add-minimal-console-client-example branch July 17, 2026 17:37
marcschier added a commit to marcschier/UA-.NETStandard that referenced this pull request Jul 23, 2026
Large merge bringing in ~60 upstream commits, most notably the
repository layout consolidation (OPCFoundation#4010) that moves the whole tree under
src/, samples/, tests/, tools/, docs/, and fuzzing/. Also includes the
repo-wide source-generated logging migration (OPCFoundation#3908/OPCFoundation#4003), Part 4 6.6
Redundancy (OPCFoundation#3918), runtime NodeSet-backed node managers (OPCFoundation#3990),
MinimalClient sample (OPCFoundation#4006), and many CTT/compliance and security fixes.

Conflict resolution:

 * UA.slnx - took upstream's new-layout solution structure and added
   our branch-only UaLens under the /samples/ folder
   (samples/Opc.Ua.Lens/Opc.Ua.Lens.csproj). Dropped the stale
   Applications/McpServer entry (McpServer already lives under master's
   /tools/ section as tools/Opc.Ua.Mcp).
 * .azurepipelines/preview.yml, signlist{Debug,Release}.txt - took
   upstream's versions wholesale (pure old->new layout path rewrites for
   upstream-managed files; UaLens was never sign-listed).

Relocations for our branch-only files that the consolidation could not
auto-move (they exist only on our side, so upstream's rename didn't
touch them):

 * Applications/Opc.Ua.Lens/ -> samples/Opc.Ua.Lens/ (alongside the
   other sample apps). Updated its csproj ProjectReferences from the old
   Stack/ + Libraries/ paths to the new src/ layout, and dropped the
   obsolete <None Remove ...Docs\NugetREADME.md> line (common.props no
   longer ships a shared root readme; each package owns its local
   NugetREADME.md, which UaLens already has).
 * Libraries/Opc.Ua.Client/UserManagement/{IUserManagementClient,
   UserManagementClient,UserManagementUser}.cs ->
   src/Opc.Ua.Client/UserManagement/ so they compile back into the
   (moved) client project.

Suppressed CA1873 in the UaLens csproj (with comment + TODO): upstream's
source-generated-logging migration enabled this analyzer repo-wide and
it flags UaLens's 146 direct ILogger.Log* call sites. Migrating UaLens
logging to [LoggerMessage] partials is tracked as follow-up.

UaLens build clean (0 warnings / 0 errors).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready Ready to merge once CI Passes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add minimal client application utilizing version 2.0 and FluentAPI

5 participants