Path: redb-route/redb.Route.Soap/Fluent/Soap.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/Fluent/Soap.cs ---- using System.Text; namespace redb.Route.Soap.Fluent; /// /// Entry point for the SOAP fluent DSL. /// /// // Call a service /// .To(Soap.Call("https://gds/air.svc").ConnectionFactory("amadeus").Operation("GetFares")) /// /// // Host a SOAP endpoint /// From(Soap.Listen("/svc/orders").Host("0.0.0.0").Port(4090).ConnectionFactory("self")) /// /// public static class Soap { /// Producer: call a SOAP service at the given endpoint URL (http ⇒ soap, https ⇒ soaps). public static SoapProducerBuilder Call(string endpointUrl) => new(endpointUrl); /// Consumer: host a SOAP receive endpoint at the given path. public static SoapConsumerBuilder Listen(string path) => new(path); } /// Fluent builder for a SOAP producer (service call) URI. public sealed class SoapProducerBuilder { private readonly string _url; private string? _connectionFactory; private string? _operation; private string? _action; private bool? _throwOnFault; internal SoapProducerBuilder(string url) => _url = url ?? throw new ArgumentNullException(nameof(url)); /// References a registered . public SoapProducerBuilder ConnectionFactory(string name) { _connectionFactory = name; return this; } /// Operation name. public SoapProducerBuilder Operation(string operation) { _operation = operation; return this; } /// Explicit SOAPAction. public SoapProducerBuilder Action(string action) { _action = action; return this; } /// /// Whether a soap:Fault in the reply fails the exchange (default true). False returns the /// fault as the reply, with redbSoap.isFault, redbSoap.faultCode and /// redbSoap.faultString to branch on. /// public SoapProducerBuilder ThrowOnFault(bool value = true) { _throwOnFault = value; return this; } /// Builds the soap:// / soaps:// URI. public string Build() { string scheme = "soap", rest = _url; if (_url.StartsWith("https://", StringComparison.OrdinalIgnoreCase)) { scheme = "soaps"; rest = _url["https://".Length..]; } else if (_url.StartsWith("http://", StringComparison.OrdinalIgnoreCase)) { scheme = "soap"; rest = _url["http://".Length..]; } var sb = new StringBuilder(scheme).Append("://").Append(rest); var sep = rest.Contains('?') ? '&' : '?'; void Append(string key, string? value) { if (string.IsNullOrEmpty(value)) return; sb.Append(sep).Append(key).Append('=').Append(Uri.EscapeDataString(value)); sep = '&'; } Append("connectionFactory", _connectionFactory); Append("operation", _operation); Append("action", _action); if (_throwOnFault is { } tof) Append("throwOnFault", tof ? "true" : "false"); return sb.ToString(); } /// Allows passing the builder directly to To(). public static implicit operator string(SoapProducerBuilder builder) => builder.Build(); } /// Fluent builder for a SOAP consumer (receive endpoint) URI. public sealed class SoapConsumerBuilder { private readonly string _path; private string _host = "0.0.0.0"; private int _port; private int _maxConcurrentRequests; private int _requestQueueLimit; private int? _rejectStatusCode; private int? _retryAfterSeconds; private long? _maxRequestBodySize; private string? _connectionFactory; private bool _ssl; private string? _sslCertPath; private SoapClientCertificateMode _clientCertificateMode = SoapClientCertificateMode.NoCertificate; private string? _allowedClientThumbprints; private bool _emitHttpCompatHeaders; internal SoapConsumerBuilder(string path) { ArgumentException.ThrowIfNullOrWhiteSpace(path); _path = path.StartsWith('/') ? path : "/" + path; } /// Bind host. public SoapConsumerBuilder Host(string host) { _host = host; return this; } /// Bind port. public SoapConsumerBuilder Port(int port) { _port = port; return this; } /// References a registered . public SoapConsumerBuilder ConnectionFactory(string name) { _connectionFactory = name; return this; } /// /// Serves the endpoint over TLS. The certificate path may be given here or left to the connection /// factory; the password belongs on the factory only, so it never becomes part of the route key. /// public SoapConsumerBuilder Ssl(string? certPath = null) { _ssl = true; _sslCertPath = certPath; return this; } /// Requires or allows a client certificate (mTLS). Only meaningful together with TLS. public SoapConsumerBuilder ClientCertificate( SoapClientCertificateMode mode, string? allowedThumbprints = null) { _clientCertificateMode = mode; _allowedClientThumbprints = allowedThumbprints; return this; } /// /// Also publishes the caller's address, path and method under redbHttp.*, so processors /// written against the HTTP transport work unchanged behind this endpoint. /// public SoapConsumerBuilder HttpCompatHeaders(bool enabled = true) { _emitHttpCompatHeaders = enabled; return this; } /// /// Admission limit: at most concurrent pipeline executions; overflow /// beyond the optional FIFO is shed with 429 + Retry-After before /// any envelope work. /// public SoapConsumerBuilder MaxConcurrentRequests(int max, int queue = 0) { _maxConcurrentRequests = max; _requestQueueLimit = queue; return this; } /// Status code for a shed request (default 429). public SoapConsumerBuilder RejectStatusCode(int statusCode) { _rejectStatusCode = statusCode; return this; } /// Retry-After value for a shed request in seconds; 0 = do not send (default 1). public SoapConsumerBuilder RetryAfterSeconds(int seconds) { _retryAfterSeconds = seconds; return this; } /// Upper bound on a request body in bytes, MTOM attachments included; 0 = no bound (default 100 MB). public SoapConsumerBuilder MaxRequestBodySize(long bytes) { _maxRequestBodySize = bytes; return this; } /// Builds the soap:/path?... (or soaps:) URI. public string Build() { // The scheme is what the component reads the TLS decision from, so TLS changes the scheme rather // than adding a parameter — the same spelling a hand-written URI uses. var sb = new StringBuilder(_ssl ? "soaps:" : "soap:").Append(_path); var sep = '?'; void Append(string key, string value) { sb.Append(sep).Append(key).Append('=').Append(Uri.EscapeDataString(value)); sep = '&'; } Append("host", _host); Append("port", _port.ToString(System.Globalization.CultureInfo.InvariantCulture)); if (!string.IsNullOrEmpty(_connectionFactory)) Append("connectionFactory", _connectionFactory); if (!string.IsNullOrEmpty(_sslCertPath)) Append("sslCertPath", _sslCertPath!); if (_clientCertificateMode != SoapClientCertificateMode.NoCertificate) Append("clientCertificateMode", _clientCertificateMode.ToString()); if (_emitHttpCompatHeaders) Append("emitHttpCompatHeaders", "true"); if (_maxConcurrentRequests > 0) Append("maxConcurrentRequests", _maxConcurrentRequests.ToString(System.Globalization.CultureInfo.InvariantCulture)); if (_requestQueueLimit > 0) Append("requestQueueLimit", _requestQueueLimit.ToString(System.Globalization.CultureInfo.InvariantCulture)); if (_rejectStatusCode is { } rsc) Append("rejectStatusCode", rsc.ToString(System.Globalization.CultureInfo.InvariantCulture)); if (_retryAfterSeconds is { } ras) Append("retryAfterSeconds", ras.ToString(System.Globalization.CultureInfo.InvariantCulture)); if (_maxRequestBodySize is { } mrb) Append("maxRequestBodySize", mrb.ToString(System.Globalization.CultureInfo.InvariantCulture)); if (!string.IsNullOrEmpty(_allowedClientThumbprints)) Append("allowedClientThumbprints", _allowedClientThumbprints!); return sb.ToString(); } /// Allows passing the builder directly to From(). public static implicit operator string(SoapConsumerBuilder builder) => builder.Build(); }