C# 如何在SOAP头中声明名称空间前缀
我使用下面的代码向soap头添加头C# 如何在SOAP头中声明名称空间前缀,c#,soap,header,namespaces,C#,Soap,Header,Namespaces,我使用下面的代码向soap头添加头 using (new OperationContextScope(client.InnerChannel)) { OperationContext.Current.OutgoingMessageHeaders.Add( MessageHeader.CreateHeader("ns:To", "", "http://###.com")); } 但是我得到了未声明的名称空间前
using (new OperationContextScope(client.InnerChannel))
{
OperationContext.Current.OutgoingMessageHeaders.Add(
MessageHeader.CreateHeader("ns:To", "", "http://###.com"));
}
但是我得到了未声明的名称空间前缀ns
错误,我需要添加xmlns:ns=”http://www.w3.org/2005/08/addressing“
到名称空间
所以我的问题是如何将名称空间前缀添加到
<s:Envelope>
<s:Header>
<ns:To>##</ns:To>
</s:Header>
</s:Envelope>
##
到
##
试试这个:
String oasisWsSecNS = "http://www.w3.org/2005/08/addressing";
XmlDocument document = new XmlDocument();
XmlElement child = document.CreateElement("To", oasisWsSecNS);
child.AppendChild(document.CreateTextNode("[value]"));
element.AppendChild(child);
context.OutgoingMessageHeaders.Add(MessageHeader.CreateHeader("Header", oasisWsSecNS, document.DocumentElement));
也许这会帮助你。。。请在下面的帖子中查看我的解决方案:@m.kudi谢谢您的回复,请输入我的代码,但不要将名称空间添加到标题中。
String oasisWsSecNS = "http://www.w3.org/2005/08/addressing";
XmlDocument document = new XmlDocument();
XmlElement child = document.CreateElement("To", oasisWsSecNS);
child.AppendChild(document.CreateTextNode("[value]"));
element.AppendChild(child);
context.OutgoingMessageHeaders.Add(MessageHeader.CreateHeader("Header", oasisWsSecNS, document.DocumentElement));