3

我有这段代码由于某种原因没有写名称或命名空间或属性

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"/>

我需要这个:

<MultiSpeakMsgHeader xmlns="http://www.multispeak.org/Version_3.0" AppName="A" AppVersion="1" CSUnits="feet" /> 

代码使用:

AddressHeader[] header = { AddressHeader.CreateAddressHeader(new MultiSpeakHeader()) };
4

1 回答 1

0

我可以添加属性,但根节点需要有前缀。我试图避免它,但没有成功。

writer.WriteXmlnsAttribute("test", this.Namespace);
writer.WriteAttributeString("AppName", "A");
writer.WriteAttributeString("AppVersion", "1");
writer.WriteAttributeString("CSUnits", "feet");
于 2015-06-08T23:26:59.637 回答