Order of the Fields in XML WCF

2

I rengo a case with a WCF that does not allow me to receive the data correctly when consuming it from an external tool, example (SOAP UI), I have the following DataContract :

[DataContract]
public class Ticket
{
    [DataMember]
    public int TicketId { get; set; }
    [DataMember]
    public int TableNumber { get; set; }
    [DataMember]
    public int ServerId { get; set; }
    [DataMember]
    public DateTime Timestamp { get; set; }
}

This is my Contract:

    [OperationContract]
    [WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped)]        
    Task<int> ExecuteATransfer(Ticket TransferRequest);

When consuming the WCF from the SOAP UI this is the initial structure:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:wcf="http://schemas.datacontract.org/2004/07/wcfPCBApp">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:ExecuteATransfer>
         <tem:TransferRequest>

            <wcf:ServerId>100</wcf:ServerId>
            <wcf:TableNumber>205</wcf:TableNumber>
            <wcf:TicketId>5894</wcf:TicketId>
            <wcf:Timestamp>2016-08-25</wcf:Timestamp>
         </tem:TransferRequest>
      </tem:ExecuteATransfer>
   </soapenv:Body>
</soapenv:Envelope>

But if you invert one of the fields in the XML structure from the SopaUI such as the DataMenber ServerId with TableNumber:

When the consumption or request is made, the ServerId field arrives empty even though the SOAP UI is assigned a specific Value:

It is possible to appreciate that the value reaches 0 when it should be 100.

    
asked by Otrebor Solrac 30.08.2016 в 17:45
source

1 answer

2

In the deserializacion WCF takes into account the order of the properties

WCF Data Member Order

It's more you'll notice that you can change it

[DataContract]
public class Ticket
{
    [DataMember(Order=2)]
    public int TicketId { get; set; }

    [DataMember(Order=0)]
    public int TableNumber { get; set; }

    [DataMember(Order=1)]
    public int ServerId { get; set; }

    [DataMember(Order=3)]
    public DateTime Timestamp { get; set; }
}

the idea is that the properties map in the order of serialized xml to soap

Order of data members

    
answered by 30.08.2016 в 18:41