我想在xmlrequest和xmlresponse中使用XML属性而不是元素,我按如下方式实现了IXmlSerializable:
public partial class Id : IXmlSerializable
{
/// <remarks/>
[XmlAttribute]
public string lmsId;
/// <remarks/>
[XmlAttribute]
public string unitId;
/// <remarks/>
[XmlAttribute]
public string lmsPresId;
/// <remarks/>
[XmlAttribute]
public string callId;
public System.Xml.Schema.XmlSchema GetSchema()
{
return null;
}
public void ReadXml(System.Xml.XmlReader reader)
{
//implement if remote callers are going to pass your object in
}
public void WriteXml(System.Xml.XmlWriter writer)
{
writer.WriteAttributeString("lmsId", lmsId.ToString());
writer.WriteAttributeString("unitId", unitId.ToString());
writer.WriteAttributeString("lmsPresId", lmsPresId.ToString());
writer.WriteAttributeString("callId", callId.ToString());
}
}
但我的服务帮助显示请求和响应为未知
我甚至尝试过XmlSerializerFormat
[System.ServiceModel.MessageContract]
public partial class Id
{
/// <remarks/>
[XmlAttribute, MessageBodyMember]
public string lmsId;
/// <remarks/>
[XmlAttribute, MessageBodyMember]
public string unitId;
/// <remarks/>
[XmlAttribute, MessageBodyMember]
public string lmsPresId;
/// <remarks/>
[XmlAttribute, MessageBodyMember]
public string callId;
}
然后我将xml中的所有内容都作为xmlElements而不是XmlAttributes获取但是我将所有数据作为元素而不是Xmlattributes。