如何使用多个 XmlElementAttribute 序列化 Soap 主体?
How I can serialize Soap body with multiple XmlElementAttribute?
我使用了 添加服务引用 并添加了 wsdl,它使用任何 class 创建文件 Reference.cs
并使用两个 XmlElementAttribute 修饰 属性。
我如何使用 filterByUser 和 includeSites 填充 Item 以便发送到网络服务器 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>
我使用了 添加服务引用 并添加了 wsdl,它使用任何 class 创建文件 Reference.cs
并使用两个 XmlElementAttribute 修饰 属性。
我如何使用 filterByUser 和 includeSites 填充 Item 以便发送到网络服务器 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>