Skip to content

Setting namespace prefix on SoapFault faultcode #1143

@staal

Description

@staal

I'm trying to steer namespace prefixes on my responses as I'm re-implementing an existing service.

I have succeeded to get it to work on my regular responses by overriding the namespace manager:

        var soapNamespaceManager = new XmlNamespaceManager(new NameTable());
        soapNamespaceManager.AddNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/");

        app.UseSoapEndpoint<ISoapEndpoint>(options =>
        {
            options.SoapSerializer = SoapSerializer.XmlSerializer;
            options.XmlNamespacePrefixOverrides = soapNamespaceManager;
        });

But I cannot get it to be correct for faults, where the namespace on the faultcode is s:Server, but should be soap:Server.

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
               xmlns:xsd="http://www.w3.org/2001/XMLSchema"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soap:Body>
        <soap:Fault>
            <faultcode>s:Server</faultcode>
            <faultstring>Delivery error</faultstring>
            <detail>
                <fault xmlns="..." xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
                    <code>22</code>
                    <reason>Delivery error</reason>
                </fault>
            </detail>
        </soap:Fault>
    </soap:Body>
</soap:Envelope>

If I add new FaultCode("Server", "http://schemas.xmlsoap.org/soap/envelope/")) to my FaultException I get <a:faultcode xmlns:a="http://schemas.xmlsoap.org/soap/envelope/">a:Server</a:faultcode> which is also off.

It looks like the underlying issue is that the s: is hardcoded in

writer.WriteElementString("faultcode", "s:" + faultException.Code.Name);

Any suggestions on how to oversteer it?

For regular responses it looks like it is the lookup of the prefix that makes it tick:

var prefix = Version.Envelope.NamespacePrefix(NamespaceManager);


An alternative would be for me to be able to re-add s as a prefix in AdditionalEnvelopeXmlnsAttributes. But those attributes are never passed through to the CustomMessage written in DefaultFaultExceptionTransformer. I tried overriding that implementation, but the initializers for the NamespaceManager and the AdditionalEnvelopeXmlnsAttributes are internal on the CustomMessage

public System.Collections.Generic.Dictionary<string, string> AdditionalEnvelopeXmlnsAttributes { get; internal set; }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions