I'm using following code to add header to soap header.
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.
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));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.