soap - Lost attribute after serialization while building XML request
问题描述
I created the request object from the class of my web service reference and assigned the enum value to the property of 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 };
I'm expecting to have the XML request with attribute "Action" inside Navigation node like below:
<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>
But after serialization I'm getting the next XML request without "Action" attribute.
<?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>
Also, below are classes from web service reference that I'm using in my request:
/// <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;
}
}
}
Any idea how to not lost the attribute "Action" after serialization?
I will appreciate any help.
解决方案
You are missing the attribute ActionSpecified
, I have added a snippet of the payload construction.
QueueAccessRQ request = new QueueAccessRQ()
{
Version = "2.0.9",
Navigation = new QueueAccessRQNavigation()
{
Action = QueueAccessRQNavigationAction.I,
ActionSpecified = true
}
};
推荐阅读
- android - 如何使用低于 23 的 Android API 的材料组件以编程方式更改按钮颜色?
- python - 熊猫,时间序列:运行时间戳后的(ids,value)计数
- php - PHP SQL 错误帮助和安全改进
- python - 如何在不超出范围或其他错误的情况下循环数百万个 Django 模型对象
- java - Android工作室,列表视图,java
- javascript - 服务器发送事件:JavaScript 事件不起作用
- javascript - 从 Angular 调用 Javascript 函数
- r - 总结列表的前 5 个元素
- python - 无法在我的模型中保存我的 admin.py 更改
- python - 如何获取 Tweet 容器的大小和文档位置