Path: redb-route/redb.Route.Soap/README.md 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/README.md ---- # redb.Route.Soap > Documentation and articles: **SOAP / WSDL web-service transport for the [redb.Route](../redb.Route) ESB framework**, oriented to Apache Camel's `camel-cxf`. Call SOAP services and host SOAP endpoints as ordinary route steps — with the two SOAP header planes, SOAP 1.1 / 1.2, faults, WS-Security (UsernameToken + XML-Signature + XML-Encryption), MTOM attachments, and `?wsdl` publishing. Schemes: `soap` (HTTP), `soaps` (HTTPS). - **Call** (`.To(...)`) — wrap a payload in an envelope, POST it, parse the response, surface a `soap:Fault`. - **Host** (`.From(...)`) — run a SOAP endpoint on the shared Kestrel server; the route handles the request and its reply becomes the response envelope. - **Both directions**, **SOAP 1.1 and 1.2**, three camel-cxf **dataFormat** modes, **WS-Security**, **MTOM**. Everything is **in-box** — `HttpClient`, the shared `redb.Route.Http.Hosting` Kestrel host, and `System.Security.Cryptography.Xml` for WS-Security. No CoreWCF, no `System.ServiceModel` runtime, no vulnerable dependency. Interop is validated against an independent SOAP stack (Node.js `soap`) in both directions, plain and MTOM. --- ## Install & register ```csharp services.AddRedbRoute(route => { route.Services.AddRedbRouteSoap(); route.AddRouteBuilder(); }); ``` `AddRedbRouteSoap()` registers the `soap` / `soaps` schemes and shares one Kestrel receive server with every other HTTP-based connector in the process (via `redb.Route.Http.Hosting`). --- ## Quick start Every endpoint works two equivalent ways — a **fluent builder** or a plain **string URI**. Use whichever reads better; the fluent builder simply emits the string form under the hood. ```csharp // Call a service — fluent From("direct://get-fares") .To(Soap.Call("https://gds/air.svc").ConnectionFactory("amadeus").Operation("GetFares")); // Call a service — string URI (identical) From("direct://get-fares") .To("soaps://gds/air.svc?connectionFactory=amadeus&operation=GetFares"); // Host a SOAP endpoint — fluent From(Soap.Listen("/svc/orders").Host("0.0.0.0").Port(4090).ConnectionFactory("orders")) .Process(handle); // Host a SOAP endpoint — string URI (identical) From("soap:/svc/orders?host=0.0.0.0&port=4090&connectionFactory=orders") .Process(handle); ``` In the default **Payload** mode the message body is the XML of `` — send a fragment, receive a fragment. No code generation, works against any service. ## Endpoint URIs If you prefer raw strings (config files, `From`/`To` with a literal), here is the full grammar. **Producer** (`.To(...)`) — `soap://` for HTTP, `soaps://` for HTTPS; the host+path is the service address: ``` soap://{host}{/path}?connectionFactory={name}&operation={op}&action={soapAction} soaps://gds/air.svc?connectionFactory=amadeus&operation=GetFares ``` **Consumer** (`.From(...)`) — `soap:` plus the receive path; the host/port are query parameters: ``` soap:/{path}?host={bind}&port={port}&connectionFactory={name} soap:/svc/orders?host=0.0.0.0&port=4090&connectionFactory=orders ``` | Query parameter | Side | Meaning | |---|---|---| | `connectionFactory` | both | Name of the registered `SoapConnectionFactory`. | | `operation` | producer | Operation name / SOAPAction. | | `action` | producer | Explicit SOAPAction (overrides the factory default). | | `throwOnFault` | producer | Whether a `soap:Fault` reply fails the exchange (default `true`). | | `host` | consumer | Bind address (`0.0.0.0` for all interfaces). | | `port` | consumer | Listen port. | The `soaps` scheme (or an `https://` URL passed to `Soap.Call`) turns on TLS. Certificates, credentials, the SOAP version and the data format live on the `SoapConnectionFactory` (below), never in the URI. --- ## Service bindings — `SoapConnectionFactory` A binding is the WSDL/endpoint, version, data format, and WS-Security material. Register it **once** by name; routes reference it with `.ConnectionFactory("name")`, so certificates and credentials never live in a URI (the same pattern as AS2 / RabbitMQ). ```csharp context.AddToRegistry("amadeus", new SoapConnectionFactory { EndpointUrl = "https://gds/air.svc", SoapVersion = SoapVersion.Soap11, DataFormat = SoapDataFormat.Payload, DefaultAction = "urn:GetFares", // WS-Security (optional) SigningCert = ourPfx, // our cert + PRIVATE key — signs outgoing, decrypts incoming EncryptCert = partnerCer, // partner's PUBLIC cert — encrypts outgoing, verifies their signature Username = "svc", Password = "secret", // UsernameToken Mtom = true, // enable MTOM/XOP attachments Wsdl = "contracts/air.wsdl", // published on GET ?wsdl (consumer) }); ``` | Property | Role | |---|---| | `EndpointUrl` | Service URL to POST to (producer) / public address (consumer). | | `SoapVersion` | `Soap11` (default) or `Soap12`. Drives Content-Type and SOAPAction placement. | | `DataFormat` | `Payload` (default), `Message`, or `Pojo`. | | `DefaultAction` | SOAPAction used when the exchange carries no `redbSoap.action`. | | `SigningCert` | Our cert **with private key**: signs outgoing, decrypts incoming. | | `EncryptCert` | Partner's public cert: encrypts outgoing, **authenticates** their signature. | | `Username` / `Password` | WS-Security UsernameToken. `Password` is `[Sensitive]` (redacted in logs). | | `RequestType` / `ResponseType` | Pojo mode: CLR types for the request (consumer) / response (producer). | | `Mtom` | Send/receive binary attachments as `multipart/related`. | | `Wsdl` | File path or inline XML; a consumer serves it on `GET ?wsdl`. | --- ## dataFormat modes (camel-cxf parity) Set `SoapConnectionFactory.DataFormat`: ### `Payload` (default) The route body is the inner `` XML. Works with any service, no codegen. The producer wraps a fragment in an envelope; the consumer hands the route the Body payload and wraps the route's reply. ### `Message` — transparent proxy The route body is the **whole envelope**, in and out. The producer sends `In.Body` verbatim (no header injection, no auto-security — those are the route's own); the consumer hands the route the entire wire envelope and returns whatever envelope the route produced. Use it to inspect, log, or forward SOAP traffic untouched. ### `Pojo` — typed objects Typed request/response via `XmlSerializer` — the .NET analogue of camel-cxf's POJO mode over JAXB document/literal. DTOs are ordinary XML-serializable types and may be generated from a WSDL with `dotnet-svcutil`. ```csharp context.AddToRegistry("air", new SoapConnectionFactory { EndpointUrl = "https://gds/air.svc", DataFormat = SoapDataFormat.Pojo, ResponseType = typeof(GetFaresResponse), // producer: reply type }); From("direct://q") .Process(e => e.In.Body = new GetFaresRequest { Route = "JFK-LHR" }) .To(Soap.Call("https://gds/air.svc").ConnectionFactory("air")); // e.Out.Body is now a GetFaresResponse ``` On a consumer set `RequestType` (the inbound type the route receives); the route's reply object is serialized back. Override the producer's response type per message with the `redbSoap.responseType` header. --- ## Two header planes SOAP has two distinct header planes, and the connector keeps them apart: 1. **Transport HTTP headers** — `SOAPAction`, `Content-Type`. Handled internally. 2. **Envelope ``** — the SOAP header block. Each child element maps to a `redbSoap.header.` exchange header (in and out). Set one on the producer and it becomes a `` child; read them on the consumer. Connector metadata carries the `redbSoap.` prefix and is **stripped before the envelope goes out** (`SoapHeaders.IsRedbHeader`), so it never leaks onto the wire. | Header | Direction | Meaning | |---|---|---| | `redbSoap.action` | in/out | SOAPAction of the request/operation. | | `redbSoap.operation` | in | Local name of the Body payload's root element (route on it). | | `redbSoap.faultCode` / `redbSoap.faultString` | in/out | Fault code / reason. Inbound: a `soap:Fault` that arrived. Outbound on a consumer reply: send this fault instead of a normal response. | | `redbSoap.isFault` | in | Producer with `throwOnFault=false`: the reply is a fault. | | `redbSoap.username` / `redbSoap.password` | in | WS-Security UsernameToken, surfaced on the consumer. | | `redbSoap.signatureValid` | in | Whether an inbound Body signature verified (see WS-Security). | | `redbSoap.responseType` | out | Pojo mode: per-message response CLR `Type`. | | `redbSoap.header.*` | in/out | Envelope `` block elements (the second plane). | --- ## SOAP 1.1 vs 1.2 and faults `SoapVersion` drives the wire: - **1.1** — `text/xml` + a separate `SOAPAction` HTTP header; faults carry `faultcode` / `faultstring`. - **1.2** — `application/soap+xml` with the action folded into the Content-Type; faults carry `Code`/`Value` and `Reason`/`Text`. A fault response surfaces on `redbSoap.faultCode` / `redbSoap.faultString` and throws `SoapFaultException` from the producer. On the consumer, a route exception becomes a `soap:Fault` (HTTP 500 for 1.1, HTTP 200 for 1.2, per convention). Both fault shapes are parsed regardless of prefix (the parser is namespace-driven, so WCF `s:` and CXF `soapenv:` envelopes read the same). ### A fault that is an answer, not a failure "No such order" is what the service is *designed* to return, and it should not read as a broken route — counted as an error, copied into a dead-letter channel, shown as a failing route to whoever supervises it. Both directions have a way to say so, and both are 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. **Answering with a fault** — put the reason on the reply and return normally: ```csharp .Process(e => e.In.Headers[SoapHeaders.FaultString] = "No order with that number") // optional: e.In.Headers[SoapHeaders.FaultCode] = "wst:FailedAuthentication"; ``` The consumer sends a `soap:Fault` and the exchange stays successful. Without a code the fault is the sender's (`soap:Sender` / `soap:Client`): a refusal about the *content* of the request will refuse the same bytes again, while `Receiver` means "retry". Throwing `SoapFaultException` still works and still means a failure — an exception the route did not intend is exactly that. **Receiving a fault** — `throwOnFault=false` on the call: ```csharp .To(Soap.Call(url).ConnectionFactory("svc").Operation("GetFares").ThrowOnFault(false)) .Choice() .When(Header(SoapHeaders.IsFault).isEqualTo(true)).To("direct://no-fares") .Otherwise().To("direct://quote") ``` The fault comes back on `Out`, with `redbSoap.isFault`, `redbSoap.faultCode` and `redbSoap.faultString` to branch on. Default stays `true` — a fault fails the exchange, as before. Mirrors `throwOnError` on the HTTP producer. --- ## WS-Security All in-box via `System.Security.Cryptography.Xml`, configured with certificates/credentials on the `SoapConnectionFactory`. Certificate roles mirror AS2: - **`SigningCert`** — our cert with private key: **signs** outgoing bodies and **decrypts** incoming ones. - **`EncryptCert`** — the partner's public cert: **encrypts** outgoing bodies and **authenticates** their incoming signature. **UsernameToken** — set `Username` (+ `Password`) and the producer prepends a `` header; the consumer surfaces them on `redbSoap.username` / `redbSoap.password`. **XML-Signature** — with `SigningCert` set the producer signs the `` (Exclusive C14N, SHA-256, `wsu:Id` reference, embedded X.509). The consumer verifies and reports `redbSoap.signatureValid`: - When **`EncryptCert` is set**, verification is **authenticated**: the signer must be that exact partner certificate (thumbprint match) and the signature must cover the `` — a forged self-signed signature or a signature over a decoy element is rejected. - When it is **not set**, only cryptographic **integrity** against the embedded key is checked (the Body was not tampered), which does **not** establish who the sender is. **XML-Encryption** — with `EncryptCert` set the producer encrypts the `` to the partner; the consumer decrypts with its `SigningCert` private key. The wire is the **standard WSS layout** real stacks produce and expect: an `` (AES session key, RSA-OAEP-wrapped) in the `` header, joined by a `ReferenceList` to the `` (AES-256-CBC) in the Body. The order is **sign-then-encrypt** outbound and **decrypt-then-verify** inbound, and the producer applies the same to responses (symmetric). Decryption also reads the legacy inline layout. ```csharp context.AddToRegistry("secured", new SoapConnectionFactory { EndpointUrl = "https://partner/svc", SigningCert = ourPfx, // sign + decrypt EncryptCert = partnerCer, // encrypt + authenticate their signature }); ``` --- ## MTOM / attachments Set `Mtom = true`. Binary attachments travel as `multipart/related` + `xop:Include` and are the [message attachments](../README.md#attachments) (`exchange.In.Attachments`), as Camel's `AttachmentMessage`, so the Body contract is untouched and the same attachments can go on to `smtp:` or come from an upload. ```csharp var msg = new Message("" + ""); msg.Attachments.Add(new Attachment { Name = "doc-1", ContentId = "doc-1", ContentType = "application/pdf", Content = AttachmentContent.FromBytes(pdfBytes), }); await producer.Process(new Exchange(msg)); ``` - **Producer.** Sends every message attachment as a part addressed by its `Content-ID`, else by its name; the reply's MTOM parts become the attachments of the reply, which replace the request ones when the pipeline moves on (a reply without parts leaves the request attachments). - **Consumer.** Every non-root part of an inbound `multipart/related` becomes a message attachment named by its `Content-ID`, with its full `Content-Type`. To reply with attachments, the route changes them (for example `Attachments.Clear()` and `Add`); a reply that holds exactly the request attachments is sent without them, so the connector does not echo the caller's own files. - In an expression: `attachments.size`, `attachmentContent('doc-1')`, `attachments[0].contentId`. The MIME parser is line-anchored, so boundary-looking bytes inside a binary part never cause a mis-split. The `redbSoap.attachments` and `redbSoap.hasAttachments` headers and the `SoapAttachment` type are gone (see `UPGRADING.md`, "Mail and SOAP attachments are message attachments"). --- ## WSDL publishing Set `SoapConnectionFactory.Wsdl` to a file path or inline XML on a consumer and it is served on `GET {path}?wsdl`, with the `` location rewritten to the address the client actually reached you on (camel-cxf `?wsdl` parity). Without a WSDL, GET is not an allowed method on the endpoint. .NET Core has no runtime WSDL *import* (by design), so the WSDL is the authored — or `dotnet-svcutil`-derived — contract, not reflected from CLR types. Pair it with `Pojo` mode for typed request/response. --- ## Telemetry & statistics Spans on the `redb.Route` activity source (`AddSource("redb.Route")`), both with `rpc.system = soap` and `redb.route.endpoint`: - **Consumer.** One `Server` span per request, `soap receive`, over the whole request, the ones refused before the envelope is read included. Its parent is the host's ASP.NET Core span when the application instruments ASP.NET Core, otherwise the caller's `traceparent`; without one it is a root. The caller's baggage is back on it, and the route's spans are its children. As a 5xx against a 4xx: a Receiver/Server fault, thrown or declared on the reply, and any other failure of the route mark it an error, a cancellation included unless the caller went away; a malformed request or a Sender/Client fault is an answer to the caller and does not. Only a `Client` (SOAP 1.1) or `Sender` (SOAP 1.2) code counts as the caller's: any other code, `wst:FailedAuthentication` included, marks the span; in SOAP 1.2 a caller fault is `Sender` with a subcode. - **Producer.** One `Client` span per call, `soap {action}`, with `rpc.method` = the action; an error for a failed call or a `soap:Fault` reply. The request carries the context of this span. - `RouteEngineOptions.EnableTelemetry = false` opens neither span. And `IEndpointStatistics` counters (`MessagesIn/Out`, `Errors`, bytes). `[Sensitive]` fields (the UsernameToken password) are redacted in logs and the TSAK dashboard, and endpoint URIs are sanitized. --- ## Fluent DSL ```csharp // Producer — builds "soaps://host/svc?connectionFactory=name&operation=GetFares" Soap.Call("https://host/svc") // http ⇒ soap, https ⇒ soaps .ConnectionFactory("name") .Operation("GetFares") // or .Action("urn:GetFares") // Consumer — builds "soap:/svc/path?host=0.0.0.0&port=4090&connectionFactory=name" Soap.Listen("/svc/path") .Host("0.0.0.0") .Port(4090) .ConnectionFactory("name") ``` Both builders implicitly convert to the endpoint URI (shown in the comments), so they drop straight into `.To(...)` / `.From(...)` — and you can pass that exact string yourself instead (see **Endpoint URIs**). --- ## Interop & boundaries **Validated** against independent stacks (zero shared code), gated `Category=Interop`; the harness is profile `soap` of the test stand `docker-compose.tests.yml`: - **Node.js `soap`** in both directions — our producer → their server, their client → our consumer — plain SOAP and MTOM (`SoapInteropTests`, `SoapMtomInteropTests`). - **Node.js `crypto` (OpenSSL)** decrypts our WSS-encrypted envelope end to end — RSA-OAEP key unwrap + AES-256-CBC — proving the encryption layout interoperates (`SoapEncryptionInteropTests`). Honest boundaries (documented in `../../docs/SOAP_CONNECTOR_PLAN.md`): - **Runtime WSDL import** is absent in .NET Core by design — use a static WSDL contract + Pojo types. - **WSDL generation from CLR types** (reflection, as CXF/CoreWCF) is not done — contract-first is the model. - **`CipherReference`** (external ciphertext) and non-OAEP key transport are not handled; UsernameToken `PasswordDigest` is treated as plaintext. Rare WS-* variants. Part of the redb.Route connector family. ## Request limits A request is bounded before the route sees it: | Parameter | Default | Description | |---|---|---| | `maxRequestBodySize` | 100 MB | Upper bound on the request body in bytes, MTOM attachments included; the HTTP server refuses a larger one. `0` = no bound. DSL: `.MaxRequestBodySize(bytes)` | The envelope is read through the core `SafeXml`: a DTD is refused, and the structure is checked while it is read, with the core's default limits (depth 256, 1024 attributes and 256 namespace declarations on an element). The check runs once before anything parses the request, and again after the body is decrypted, since anyone can encrypt for our certificate. A request over a limit is a `Client` (SOAP 1.1) or `Sender` (SOAP 1.2) fault that names the limit, and never reaches the route. The sender reads the service's answers with the same limits. ## Concurrency limits Kestrel executes as many handlers as requests arrive; without a limit a route has no ceiling. The admission limit caps concurrent pipeline executions per endpoint and sheds the overflow BEFORE any pipeline work (load shedding, not backpressure): | Parameter | Default | Description | |---|---|---| | `maxConcurrentRequests` | `0` (unlimited) | Max concurrent pipeline executions | | `requestQueueLimit` | `0` | Requests over the limit that WAIT (FIFO) instead of being rejected | | `rejectStatusCode` | `429` | Status for a shed request | | `retryAfterSeconds` | `1` | `Retry-After` header value; `0` = do not send | A shed request is answered before an exchange exists: it appears in the endpoint's `Rejected` counter, not in `MessagesIn` or `Errors`. The limit is strictly per endpoint — other routes on the same listener keep their own budget. For "slow down but do not drop" semantics use `.Threads(n)` in the route instead; the two compose (the limit sheds at the door, Threads paces inside).