I have a C# WCF REST Service which allows the addition of a bookmark, by sending an HTTP POST request with the bookmark serialised in XML. I have specified the operation contract for the service, which picks up the xml and automatically deserialises the object for me. My problem is that the deserialisation only works correctly if the XML elements in the request are given in alphabetical order, and the values for any elements that are out of order are not populated.
This behaviour has been reported elsewhere: http://bit.ly/WUz6
I find this to be quite unsatisfactory; I consider the requirement to construct the XML in a specific order to be unnecessary, and a major headache. This is a major requirement to add to all clients of the service, and a source of potentially difficult problems to debug.
Is it possible to direct WCF to be XML element order agnostic?
Some further details for clarification purposes:
My operation contract looks like this:
[OperationContract]
[WebInvoke(Method="POST", UriTemplate = "/{username}/bookmarks", ResponseFormat = WebMessageFormat.Xml)]
public void PostBookmark(string username, RestBookmark newBookmark);
The RestMessage looks as follows:
[DataContract(Name = "Bookmark", Namespace = "")]
public class RestBookmark
{
[DataMember]
public string BookmarkMd5 { get; set; }
[DataMember]
public string Url { get; set; }
[DataMember]
public string UserName { get; set; }
[DataMember]
public string Title { get; set; }
[DataMember]
public string Description { get; set; }
}
If I send the following XML message, then only the UserName property of the RestMessage object will be populated when PostBookmark() is invoked:
<?xml version="1.0"?><Bookmark><UserName>nick.street</UserName><Url>http://www.stackoverflow.com</Url><BookmarkMd5>f184eb3347cf94f6ce5f5fc2844e3bdd</BookmarkMd5><Description>Developer Forum</Description><Title>Stack Overflow</Title></Bookmark>