如何使用多个XmlElementAttribute序列化Soap主体



我使用了添加服务引用和添加wsdl,它们使用任何类创建文件Reference.cs,并使用两个XmlElementAttribute装饰属性。

如何使用filterByUser和includeSites填充Item以便发送到Web服务器soap?

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.3761.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="orghierarchy.interfaces.com")]
public partial class GetOrgHierarchyRequest : object, System.ComponentModel.INotifyPropertyChanged {
private object itemField;        
[System.Xml.Serialization.XmlElementAttribute("filterByUser", typeof(string), Order=0)]
[System.Xml.Serialization.XmlElementAttribute("includeSites", typeof(bool), Order=0)]
public object Item {
get {
return this.itemField;
}
set {
this.itemField = value;
this.RaisePropertyChanged("Item");
}
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName) {
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null)) {
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}

我认为XmlElementAttribute用于根据设置为Item属性的值的类型来选择要使用的字段名。

var obj = new GetOrgHierarchyRequest
{
Item = "123"
};

生成XML:

<GetOrgHierarchyRequest>
<filterByUser xmlns="orghierarchy.interfaces.com">123</filterByUser>
</GetOrgHierarchyRequest>

var obj = new GetOrgHierarchyRequest
{
Item = true
};

产生

<GetOrgHierarchyRequest>
<includeSites xmlns="orghierarchy.interfaces.com">true</includeSites>
</GetOrgHierarchyRequest>

相关内容

  • 没有找到相关文章

最新更新