Files
Copilot f95d65754d Register mandatory opc.tcp transport in AddOpcUa (make AddOpcTcpTransport optional) (#4074)
# Description

`AddOpcUa()` did not register an `ITransportBindingRegistry`. The client
resolves it with `GetRequiredService(...)`, so a client built with
`AddOpcUa().AddClient(...)` threw during managed-session creation unless
`AddOpcTcpTransport()` was also called. (Servers tolerated a missing
registry via `ServerBase`'s lazy `WithDefaultTcp()` fallback, which is
why `MinimalBoilerServer` worked but `MinimalClient` did not.)

This change makes the mandatory `opc.tcp` transport always available
while keeping it overridable and removable, then reverts the sample
workaround.

## Changes

- **`AddOpcUa()` seeds the mandatory transport.**
`AddTransportBindingRegistry()` now seeds the registry with the
raw-socket `opc.tcp` secure-channel listener and tcp connection channel
factories **before** running the registered
`ITransportBindingConfigurator`s, and `AddOpcUa()` calls it.
`AddOpcTcpTransport()` is now optional (kept for backward
compatibility).
- **Overridable.** Because the seed runs before configurators,
`AddKestrelOpcTcpTransport()` / `AddHttpsTransport()` /
`AddWssTransport()` / `AddCustomTransport<,>()` still override the
seeded defaults last-writer-wins per URI scheme — now without needing
`AddOpcTcpTransport()` first.
- **Removable.** Added `RemoveListenerFactory(scheme)` /
`RemoveChannelFactory(scheme)` to `ITransportBindingRegistry` (+
`DefaultTransportBindingRegistry`) so an implementer can unregister the
seeded defaults from a plain `ITransportBindingConfigurator` — no fluent
API required.
- **Sample.** Reverted the `MinimalClient` `.AddOpcTcpTransport()`
workaround; it now connects with just `.AddOpcUa().AddClient(...)`.
- Small note in `docs/Transports.md` that `AddOpcTcpTransport()` is
optional.

## Tests / validation

- New/updated unit tests in `TransportBindingRegistryTests`:
mandatory-`opc.tcp`-by-default,
override-default-without-`AddOpcTcpTransport`,
implementer-can-unregister-default, and `Remove*` unit tests; updated
`ParallelServiceProvidersHaveIndependentRegistries` for the seeded
default.
- Client DI regression test in `ClientDiFluentApiTests`
(`AddOpcUa().AddClient(...)` resolves the registry + channel manager
without an explicit tcp transport).
- Updated the `SpyTransportBindingRegistry` test double for the two new
interface members.
- **End-to-end:** started `MinimalBoilerServer` and ran `MinimalClient
--auto-accept` → discovered a `SignAndEncrypt` / `Basic256Sha256`
endpoint, connected, browsed the Objects folder, read
`ServerStatus.CurrentTime`, and created a subscription (exit code 0)
with no `AddOpcTcpTransport()`.
- **Green locally:** `Opc.Ua.Core.Tests` (4123 passed),
`Opc.Ua.Client.Tests` (1962 passed), `Opc.Ua.Server.Tests` Hosting (141
passed) on **net10.0**; transport + client-DI tests on **net48**;
`Opc.Ua.Core` builds with 0 warnings.

## Related Issues

Tracked by the linked issue.

## Checklist

- [ ] I have signed the
[CLA](https://opcfoundation.org/license/cla/ContributorLicenseAgreementv1.0.pdf)
and read the
[CONTRIBUTING](https://github.com/OPCFoundation/UA-.NETStandard/blob/master/CONTRIBUTING.md)
doc.
- [x] I have added tests that prove my fix is effective or that my
feature works and increased code coverage.
- [x] I have added all necessary documentation.
- [x] 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**, and all passed.
- [ ] I fixed **all** failing and flaky tests in the CI pipelines and
**all** CodeQL warnings.
- [x] I have addressed **all** PR feedback received.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Marc Schier <marcschier@hotmail.com>
Co-authored-by: Marc Schier <marcschier@users.noreply.github.com>
2026-07-23 07:26:19 +02:00
..