WCF MessageHeader Won't Write Namespace
本文关键字:Write Namespace MessageHeader Won WCF | 更新日期: 2023-09-27 18:01:50
这段代码由于某些原因没有写名称,名称空间或属性
public class MultiSpeakHeader : MessageHeader
{
protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
{
writer.WriteAttributeString("AppName", "A");
writer.WriteAttributeString("AppVersion", "1");
writer.WriteAttributeString("CSUnits", "feet");
}
public override string Name
{
get { return "MultiSpeakMsgHeader"; }
}
public override string Namespace
{
get { return "http://www.multispeak.org/Version_3.0"; }
}
}
类this实例的结果如下:
<MultiSpeakHeader xmlns="http://schemas.datacontract.org/2004/07/my.app" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"/>
i need this:
<MultiSpeakMsgHeader xmlns="http://www.multispeak.org/Version_3.0" AppName="A" AppVersion="1" CSUnits="feet" />
代码使用:
AddressHeader[] header = { AddressHeader.CreateAddressHeader(new MultiSpeakHeader()) };
我可以添加属性,但根节点需要有前缀。我试图避开它,但没有成功。
writer.WriteXmlnsAttribute("test", this.Namespace);
writer.WriteAttributeString("AppName", "A");
writer.WriteAttributeString("AppVersion", "1");
writer.WriteAttributeString("CSUnits", "feet");