Path: redb-route/redb.Route.Soap/SoapWsdl.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/SoapWsdl.cs
----
using System.Xml.Linq;
using redb.Route.Core;
namespace redb.Route.Soap;
///
/// WSDL publishing for a SOAP consumer (camel-cxf ?wsdl parity). .NET Core has no runtime WSDL
/// import (by design), but publishing a static contract is straightforward: a consumer whose
/// is set serves it on GET …?wsdl, with the
/// <soap:address> location rewritten to the address the client actually reached us on. The WSDL
/// itself is authored (or dotnet-svcutil-derived), not generated from types — the honest boundary.
///
internal static class SoapWsdl
{
/// Resolves the configured WSDL: inline XML as-is, otherwise a file path to read.
public static string? Load(string? wsdlPathOrXml)
{
if (string.IsNullOrWhiteSpace(wsdlPathOrXml)) return null;
var trimmed = wsdlPathOrXml.TrimStart();
if (trimmed.StartsWith('<')) return wsdlPathOrXml; // inline WSDL XML
// Looks like a path: read it, or return null (⇒ 404) rather than serving a bogus path string as WSDL.
return File.Exists(wsdlPathOrXml) ? File.ReadAllText(wsdlPathOrXml) : null;
}
///
/// Rewrites every <soap:address> / <soap12:address> location to
/// so a client that fetched the WSDL posts back to the real address.
/// Best-effort: malformed WSDL is returned unchanged.
///
public static string RewriteAddress(string wsdlXml, string endpointUrl)
{
try
{
var doc = SafeXml.Parse(wsdlXml);
var addresses = doc.Descendants()
.Where(e => e.Name.LocalName == "address"
&& e.Name.NamespaceName.Contains("wsdl/soap", StringComparison.OrdinalIgnoreCase))
.ToList();
if (addresses.Count == 0) return wsdlXml;
foreach (var addr in addresses)
addr.SetAttributeValue("location", endpointUrl);
return doc.Declaration is null ? doc.ToString() : doc.Declaration + Environment.NewLine + doc.ToString();
}
catch
{
return wsdlXml;
}
}
}