Path: redb-route/redb.Route.Soap/SoapPojo.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/SoapPojo.cs ---- using System.Collections.Concurrent; using System.Xml; using System.Xml.Serialization; namespace redb.Route.Soap; /// /// Pojo dataFormat: typed request/response bodies via — the .NET analogue of /// camel-cxf's POJO mode over JAXB document/literal. The body element the serializer emits becomes the /// <soap:Body> payload; the response payload deserializes into the configured CLR type. DTOs are /// ordinary XML-serializable types and may be generated from a WSDL with dotnet-svcutil. No WCF /// runtime and no vulnerable CoreWCF dependency. /// internal static class SoapPojo { // Weak per type: a type of an unloadable module (collectible load context) does not stay alive in this cache. private static readonly System.Runtime.CompilerServices.ConditionalWeakTable Cache = new(); private static XmlSerializer For(Type t) => Cache.GetValue(t, static x => new XmlSerializer(x)); /// Serializes a CLR object to an XML fragment (no declaration) for embedding in the SOAP body. public static string Serialize(object body) { var ser = For(body.GetType()); // Suppress the xsi/xsd namespace noise XmlSerializer adds by default. var ns = new XmlSerializerNamespaces(); ns.Add(string.Empty, string.Empty); var settings = new XmlWriterSettings { OmitXmlDeclaration = true, Indent = false }; using var sw = new StringWriter(); using (var xw = XmlWriter.Create(sw, settings)) ser.Serialize(xw, body, ns); return sw.ToString(); } /// Deserializes a SOAP body XML fragment into the given CLR type. public static object? Deserialize(string bodyXml, Type type) { if (string.IsNullOrWhiteSpace(bodyXml)) return null; var ser = For(type); using var sr = new StringReader(bodyXml); return ser.Deserialize(sr); } }