Ralph McArthur
Ralph McArthur

Reputation: 385

Data Member Order and XML Deserialization

I have a RESTful WCF application that makes use of custom classes as service method parameters. These classes are decorated with the [DataContract] attribute and each of their properties is decorated with the [DataMember] attribute.

The deserializer works consistent with the following "Data Member Order" page at MSDN: http://msdn.microsoft.com/en-us/library/ms729813.aspx.

That is, it expects the elements in XML formatted input data to follow the order so described. In fact, if one of the elements is out of order, after deserialization it does not have the submitted value but rather is null.

Is there a good way to allow the calling program to order the xml elements freely (i.e., in any order) and to have the deserialization come out right for every ordering of the elements?

Upvotes: 2

Views: 2925

Answers (1)

John Saunders
John Saunders

Reputation: 161783

Most XML does not permit elements to be entered in arbitrary order. There's no good reason to permit this, as far as I know.

The Data Contract Serializer does not support this at all. It would add overhead, and provide no value.

Why can't your callers just send the correct XML?

Upvotes: 2

Related Questions