简体   繁体   English

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

[英]How to declared namespace prefix in SOAP header

I'm using following code to add header to soap header.我正在使用以下代码将标头添加到soap标头。

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

But I got undeclared namespace prefix ns error, I will need add xmlns:ns="http://www.w3.org/2005/08/addressing" to name space.但是我得到了undeclared namespace prefix ns错误,我需要将xmlns:ns="http://www.w3.org/2005/08/addressing"到命名空间。

So my question is how to add namespace prefix to所以我的问题是如何将命名空间前缀添加到

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

To

<s:Envelope>
    <s:Header xmlns:ns="http://www.w3.org/2005/08/addressing">
        <ns:To>##</ns:To>
    </s:Header>
</s:Envelope>

Try this:尝试这个:

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