首页 > 解决方案 > 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.

标签: soapsabre

解决方案


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
    }
};

推荐阅读