我从Web服务引用的类中创建了请求对象,并将枚举值分配给object的属性。
SWS.QueueAccessLLSRQ.QueueAccessRQ request = new SWS.QueueAccessLLSRQ.QueueAccessRQ();
request.Version = "2.0.9";
request.Navigation = new SWS.QueueAccessLLSRQ.QueueAccessRQNavigation() { Action = SWS.QueueAccessLLSRQ.QueueAccessRQNavigationAction.I };
我希望在Navigation节点中有一个带有属性“Action”的XML请求,如下所示:
<QueueAccessRQ xmlns="http://webservices.sabre.com/sabreXML/2011/10" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Version="2.0.9"> <Navigation Action="QR"/></QueueAccessRQ>
但是在序列化后我得到了没有“Action”属性的下一个XML请求。
<?xml version="1.0"?><QueueAccessRQ Version="2.0.9" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><Navigation xmlns="http://webservices.sabre.com/sabreXML/2011/10"/></QueueAccessRQ>
此外,下面是我在请求中使用的Web服务引用的类:
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.7.2117.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://webservices.sabre.com/sabreXML/2011/10")]
public partial class QueueAccessRQ {
private QueueAccessRQNavigation navigationField;
private QueueAccessRQQueueIdentifier queueIdentifierField;
private QueueAccessRQSelection[] selectionField;
private bool returnHostCommandField;
private bool returnHostCommandFieldSpecified;
private System.DateTime timeStampField;
private bool timeStampFieldSpecified;
private string versionField;
public QueueAccessRQ() {
this.versionField = "2.0.9";
}
/// <remarks/>
public QueueAccessRQNavigation Navigation {
get {
return this.navigationField;
}
set {
this.navigationField = value;
}
}
/// <remarks/>
public QueueAccessRQQueueIdentifier QueueIdentifier {
get {
return this.queueIdentifierField;
}
set {
this.queueIdentifierField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Selection")]
public QueueAccessRQSelection[] Selection {
get {
return this.selectionField;
}
set {
this.selectionField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public bool ReturnHostCommand {
get {
return this.returnHostCommandField;
}
set {
this.returnHostCommandField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool ReturnHostCommandSpecified {
get {
return this.returnHostCommandFieldSpecified;
}
set {
this.returnHostCommandFieldSpecified = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public System.DateTime TimeStamp {
get {
return this.timeStampField;
}
set {
this.timeStampField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool TimeStampSpecified {
get {
return this.timeStampFieldSpecified;
}
set {
this.timeStampFieldSpecified = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string Version {
get {
return this.versionField;
}
set {
this.versionField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute( "System.Xml", "4.7.2117.0" )]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute( "code" )]
[System.Xml.Serialization.XmlTypeAttribute( AnonymousType = true, Namespace = "http://webservices.sabre.com/sabreXML/2011/10" )]
public partial class QueueAccessRQNavigation {
private QueueAccessRQNavigationAction actionField;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public QueueAccessRQNavigationAction Action
{
get
{
return this.actionField;
}
set
{
this.actionField = value;
}
}
}
知道如何在序列化后不丢失属性“Action”吗?
我将不胜感激。
答案 0 :(得分:1)
您缺少属性ActionSpecified
,我添加了一个有效负载构造的片段。
QueueAccessRQ request = new QueueAccessRQ()
{
Version = "2.0.9",
Navigation = new QueueAccessRQNavigation()
{
Action = QueueAccessRQNavigationAction.I,
ActionSpecified = true
}
};