【发布时间】:2012-04-26 11:38:33
【问题描述】:
我在我的 WCF 应用程序中使用自定义编码器来写出 SOAP 消息 XML。当我使用 WCF 中内置的默认 XML textMessageEncoding 时,这很好,但是当我使用自定义编码器时,我遇到了命名空间的问题 - 下面的 xmlns:a 标记(在元素和元素中) ) 为两个不同的命名空间定义了两次,这会在解析时导致服务端出现问题
<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>
关于如何解决此问题的任何想法?我在自定义编码器中使用 C# XmlWriter 来编写 XML,这似乎是导致问题的原因。
另外,我如何让XmlWriter 为上面的<Action> 标记使用前缀,以便它是<a:Action>,而不是为每个声明使用xmlns -
<Action a:mustUnderstand="1" u:Id="_3" xmlns="http://www.w3.org/2005/08/addressing"
这是我的 XmlWriterSettings
XmlWriterSettings writerSettings = new XmlWriterSettings();
writerSettings.Encoding = Encoding.GetEncoding(factory.CharSet);
writerSettings.OmitXmlDeclaration = true;
writerSettings.NamespaceHandling = NamespaceHandling.OmitDuplicates;
【问题讨论】:
标签: c# xml wcf soap xml-namespaces