繁体   English   中英

如何在 SOAP 标头中声明命名空间前缀

[英]How to declared namespace prefix in SOAP header

我正在使用以下代码将标头添加到soap标头。

using (new OperationContextScope(client.InnerChannel))
{
    OperationContext.Current.OutgoingMessageHeaders.Add(
        MessageHeader.CreateHeader("ns:To", "", "http://###.com"));                                
}

但是我得到了undeclared namespace prefix ns错误,我需要将xmlns:ns="http://www.w3.org/2005/08/addressing"到命名空间。

所以我的问题是如何将命名空间前缀添加到

<s:Envelope>
    <s:Header>
        <ns:To>##</ns:To>
    </s:Header>
</s:Envelope>

<s:Envelope>
    <s:Header xmlns:ns="http://www.w3.org/2005/08/addressing">
        <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));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM