Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在SOAP头中声明名称空间前缀_C#_Soap_Header_Namespaces - Fatal编程技术网

C# 如何在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")); } 但是我得到了未声明的名称空间前

我使用下面的代码向soap头添加头

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));