Path: redb-route/redb.Route.Soap/SoapComponent.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.Soap/SoapComponent.cs
----
using redb.Route.Abstractions;
using redb.Route.Core;
using redb.Route.Extensions;
using redb.Route.Http;
namespace redb.Route.Soap;
// ── Component ────────────────────────────────────────────────────────────────
///
/// SOAP / WSDL transport component (oriented to Apache Camel camel-cxf). Schemes: soap (HTTP)
/// and soaps (HTTPS). Producer calls a service; consumer hosts a SOAP endpoint on the shared Kestrel
/// host. Baseline is in-box (HttpClient + Http.Hosting + System.Security.Cryptography.Xml); typed WSDL (Pojo)
/// and CoreWCF ?wsdl publishing are not part of it.
///
public sealed class SoapComponent : ComponentBase
{
///
public override string Scheme => "soap";
/// HTTPS variant of the SOAP scheme.
public override IReadOnlyList AlternateSchemes => ["soaps"];
/// Shared Kestrel host for the SOAP receive endpoint (set from DI; used by the consumer).
public SharedHttpServerManager? ServerManager { get; set; }
private readonly Lazy _ownServer = new(() => new SharedHttpServerManager());
///
/// The receive server. Resolution order: explicitly assigned → the context's DI singleton → a
/// lazily-created own instance (standalone/test). The DI step matters for module hosts that add
/// the component by scanning rather than through the extension method, so nothing ever assigns
/// while the one shared manager sits in the container.
///
internal SharedHttpServerManager Server =>
ServerManager
?? Context.Resolve()
?? _ownServer.Value;
///
public override IEndpoint CreateEndpoint(EndpointUri uri)
{
ArgumentNullException.ThrowIfNull(uri);
var options = new SoapEndpointOptions();
options.BindFromUri(uri.RawParameters);
options.Path = uri.Path;
// The scheme carries the TLS decision: soaps ⇒ HTTPS.
if (string.Equals(uri.Scheme, "soaps", StringComparison.OrdinalIgnoreCase))
options.UseTls = true;
options.Validate();
return new SoapEndpoint(uri, this, options);
}
///
public override async ValueTask DisposeAsync()
{
if (_ownServer.IsValueCreated)
await _ownServer.Value.DisposeAsync().ConfigureAwait(false);
await base.DisposeAsync().ConfigureAwait(false);
}
}
// ── Options ──────────────────────────────────────────────────────────────────
/// Whether the consumer requires, allows, or ignores a client certificate (mTLS).
public enum SoapClientCertificateMode
{
/// No client certificate is requested. Default.
NoCertificate,
/// A certificate is requested; the call proceeds when the client presents none.
AllowCertificate,
/// A certificate is required; the handshake fails without one.
RequireCertificate,
}
/// Options for a SOAP endpoint.
public sealed class SoapEndpointOptions : EndpointOptions
{
/// Path from the URI (producer host+path, or consumer receive path).
public string Path { get; set; } = string.Empty;
/// Name of the registered .
[RegistryReference(typeof(SoapConnectionFactory))]
public string? ConnectionFactory { get; set; }
/// Operation name / SOAPAction override for a producer call.
public string? Operation { get; set; }
///
/// Whether a soap:Fault in the reply fails the exchange (default true). Set false when the
/// fault is an answer the service is designed to give: the reply comes back on Out, the
/// fault code and reason on redbSoap.faultCode / redbSoap.faultString, and
/// redbSoap.isFault says which kind of reply arrived. Explicit rather than inferred from
/// the fault code: a Sender fault can be a bug in the route just as easily as a business answer,
/// and only the author knows which. Mirrors throwOnError on the HTTP producer.
///
public bool ThrowOnFault { get; set; } = true;
/// Explicit SOAPAction (overrides the factory default).
public string? Action { get; set; }
/// Consumer bind host.
public string Host { get; set; } = "0.0.0.0";
/// Consumer bind port.
public int Port { get; set; }
/// HTTPS/TLS. Set automatically when the URI scheme is soaps.
public bool UseTls { get; set; }
///
/// Path to the PFX certificate the consumer serves TLS with. Required alongside
/// unless a named supplies it.
///
public string? SslCertPath { get; set; }
/// Password for the PFX certificate.
[Sensitive]
public string? SslCertPassword { get; set; }
/// Client-certificate policy (mTLS) for the consumer. Requires .
public SoapClientCertificateMode ClientCertificateMode { get; set; } = SoapClientCertificateMode.NoCertificate;
///
/// Comma-separated thumbprints of accepted client certificates. When set, a presented certificate
/// whose thumbprint is not listed is rejected even if its chain validates.
///
public string? AllowedClientThumbprints { get; set; }
///
/// Also publish the caller's address, path and method under redbHttp.*, so processors written
/// against the HTTP transport (rate limiting, lockout, device metadata) work unchanged behind a SOAP
/// endpoint. Default: false — the connector's own redbSoap.* headers always carry the same
/// facts, and writing into another transport's namespace should be asked for.
///
public bool EmitHttpCompatHeaders { get; set; }
// ── Admission limit (HTTP_CONCURRENCY_LIMITS_PLAN) ──
///
/// Maximum concurrent executions of this consumer's pipeline. 0 (default) = unlimited.
/// Overflow beyond the limit and is shed with
/// before any pipeline work.
///
public int MaxConcurrentRequests { get; set; }
/// Requests over the limit that WAIT for a permit (FIFO). 0 (default) = reject immediately.
public int RequestQueueLimit { get; set; }
/// Status code for a shed request. Default 429 Too Many Requests.
public int RejectStatusCode { get; set; } = 429;
/// Value of the Retry-After header on a shed request; 0 = do not send it. Default 1.
public int RetryAfterSeconds { get; set; } = 1;
/// Default : 100 MB, room for MTOM attachments.
public const long DefaultMaxRequestBodySize = 100L * 1024 * 1024;
///
/// Upper bound on a request body in bytes, MTOM attachments included; a larger request is refused by the HTTP
/// server before the consumer reads it. 0 = no bound. Default .
///
public long MaxRequestBodySize { get; set; } = DefaultMaxRequestBodySize;
///
public override void Validate()
{
// Minimal. Full fail-fast (version/operation/cert checks) lands with the producer/consumer.
ConcurrencyLimitOptions.ValidateShape(MaxConcurrentRequests, RequestQueueLimit, RejectStatusCode, RetryAfterSeconds);
if (MaxRequestBodySize < 0)
throw new ArgumentOutOfRangeException(nameof(MaxRequestBodySize), MaxRequestBodySize, "SOAP maxRequestBodySize must not be negative.");
}
}
// ── Endpoint ─────────────────────────────────────────────────────────────────
/// SOAP endpoint. Producer calls a service; consumer hosts a receive endpoint.
public sealed class SoapEndpoint : EndpointBase
{
private readonly SoapEndpointOptions _options;
internal SoapEndpoint(EndpointUri uri, SoapComponent component, SoapEndpointOptions options)
: base(uri, component, options)
=> _options = options;
internal SoapEndpointOptions SoapOptions => _options;
///
public override IProducer CreateProducer() => new SoapProducer(this);
///
public override IConsumer CreateConsumer(IProcessor processor)
=> new SoapConsumer(this, processor, ((SoapComponent)Component).Server);
}