Setting namespace prefix on SoapFault faultcode
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 https://github.com/DigDes/SoapCore/blob/aa5d590b3542cdf04b58358981cb9381bf699395/src/SoapCore/FaultBodyWriter.cs#L122
Any suggestions on how to oversteer it?
For regular responses it looks like it is the lookup of the prefix that makes it tick: https://github.com/DigDes/SoapCore/blob/aa5d590b3542cdf04b58358981cb9381bf699395/src/SoapCore/CustomMessage.cs#L46
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
https://github.com/DigDes/SoapCore/blob/aa5d590b3542cdf04b58358981cb9381bf699395/src/SoapCore/CustomMessage.cs#L21
ProvideFault accepts an xmlNamespaceManager that it uses for the message, but it should probably pass that xmlNamespaceManager along to FaultBodyWriter, like we do for MetaBodyWriter.
https://github.com/DigDes/SoapCore/blob/aa5d590b3542cdf04b58358981cb9381bf699395/src/SoapCore/DefaultFaultExceptionTransformer.cs#L28
Feel like submitting a PR?
This might be a breaking change in rare cases but I think it would be fine.
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.