WCF: Is the order of elements in an XML that is posted to a Rest service important?
I have been debugging a Rest Service for a while and I 开发者_StackOverflowhave realized that if I post (via POST method) this file
<RegionDTO xmlns="http://www.mysite.com/api">
<id>4</id>
<country_id>1</country_id>
<name>This is the name</name>
</RegionDTO>
I get this RegionDTO
object populated:
RegionDTO.id --> 4
RegionDTO.name --> "This is the name" RegionDTO.country_id --> nullAnd If I re-order the elements of this xml to this:
<RegionDTO xmlns="http://www.mysite.com/api">
<country_id>1</country_id>
<id>4</id>
<name>This is the name</name>
</RegionDTO>
I get this RegionDTO
object correctly populated:
RegionDTO.id --> 4
RegionDTO.name --> "This is the name" RegionDTO.country_id --> 1Technical specification? .NET 4, self hosted
Finally I found the answer:
The default serializer used by WCF is "DataContractSerializer". By default, Local elements are mapped in alphabetical order
Ref: http://www.pluralsight-training.net/microsoft/olt/Course/Toc.aspx?n=wcf-design-concepts (in "[DataContract] mapping" chapter)
精彩评论