I'm using a custom encoder in my WCF application to write out the SOAP message XML. When I use the default XML textMessageEncoding
built into WCF it's fine, but when I use a custom encoder I get a problem with the namespaces - the xmlns:a tag below (in the element and the element) is defined twice for two different namespaces and this is causing problems on the service side when parsing
<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Action a:mustUnderstand="1" u:Id="_3" xmlns="http://www.w3.org/2005/08/addressing" **xmlns:a="http://schemas.xmlsoap.org/soap/envelope/"**></Action>
<MessageID u:Id="_4" xmlns="http://www.w3.org/2005/08/addressing">
<!--Omitted-->
</MessageID>
<ActivityId CorrelationId="1" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">
<!--Omitted-->
</ActivityId>
Any idea on how to fix this issue? I'm using the C# XmlWriter
in the custom encoder to write the XML and that's what seems to be causing the issue.
Also, how do I get the XmlWriter
to use a prefix for the <Action>
tag above so that it's <a:Action>
rather than using the xmlns for every declaration -
<Action a:mustUnderstand="1" u:Id="_3" xmlns="http://www.w3.org/2005/08/addressing"
Here's my XmlWriterSettings
XmlWriterSettings writerSettings = new XmlWriterSettings();
writerSettings.Encoding = Encoding.GetEncoding(factory.CharSet);
writerSettings.OmitXmlDeclaration = true;
writerSettings.NamespaceHandling = NamespaceHandling.OmitDuplicates;