WCF DataContractSerializer Learns the Alphabet

Let’s say you have a WCF web ser­vice with REST­ful bind­ings that accepts com­plex objects and you’re hav­ing trou­ble fig­ur­ing out why some of your prop­er­ties and fields on the com­plex objects never seem to seri­al­ize prop­erly. Maybe you’ve even popped open Wire­shark and you know that the data is being put on the wire but for what­ever rea­son, some of it never shows up on the server. It’s appar­ently ran­dom and not related to the data type of the field being serialized.

Well, my lit­tle frus­trated hacker, try putting the fields in your com­plex object on the client side in alpha­bet­i­cal order and see if that doesn’t just cheer you right up. You see, the Dat­a­Con­tract­Se­ri­al­izer which is the seri­al­iza­tion object for WCF seri­al­izes the data in alpha­bet­i­cal order. That’s just how it rolls. And part of how it rolls is dic­tat­ing to the client what order their XML has to be in.

I’m sure there’s a rea­son for it. And I’d love to know what it is. Since I just spent 12 hours fig­ur­ing it out. Part of me thinks it’s Microsoft giv­ing REST the bird but never attribute to mal­ice what can be explained by igno­rance and all that. Meh.

No Comments

Leave a Reply

Your email is never shared.Required fields are marked *