tags:

views:

324

answers:

1

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?

A: 

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?

John Saunders
John, thanks for your answer. You said "the Data Contract Serializer does not support this at all." Can you point me to Microsoft documentation that says this directly, or did you put it together from various sources?
Ralph McArthur
@Ralph: you said it yourself: "it expects the elements in XML formatted input data to follow the order so described". Also, the various write-ups over the years on the differences between data contract serialization and XML serialization have made it clear data contract serialization is meant to be fast and simple. Choices are not "simple", and they add no value.
John Saunders
@Ralph: Please update your question to say why you want to do this. Why can't your callers just send the correct XML?
John Saunders
@John: my callers can, in fact, "send the correct XML." I was pursuing the plausibility of meeting a requirement that came not from them. What I read about the Data Contract Serializer is for sure the default behavior. I was trying to nail down whether it is the only behavior. I accept that following order is the normal way of using XML, and I am marking your answer as the solution. Thanks again.
Ralph McArthur
@Ralph: I once had a manager ask me the same question. In my case, looking at him like he was both crazy and stupid solved the problem.
John Saunders