Reputation: 608
I'm building a rest api in C# - and I'm setting up some POST's - here's the interface:
[SecurityTokenValidator("Registered Users")]
[OperationContract]
[WebInvoke(ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Xml, UriTemplate = "camps/{campid}/markings/{token}", Method = "POST")]
MarkingDto InsertMarking(string campid, string token, MarkingDto markingDto);
And here's my MarkingDto
[DataContract(Namespace = "FreeBeer")]
public class MarkingDto
{
[DataMember] public int Id;
[DataMember] public decimal Latitude;
[DataMember] public decimal Longitude;
[DataMember] public string MarkingType;
[DataMember] public DateTime DateTime;
}
In building up a test POST in Fiddler - I'm noticing if my RequestBody isn't in Alphabetical order - some items come up null or zero. For instance - if the request body is like so - where Longitude comes BEFORE Latitude - Latitude will be zero (0).
<MarkingDto xmlns="BigGameLogic">
<Longitude>456</Longitude>
<Latitude>123</Latitude>
<MarkingType>Scrape</MarkingType>
</MarkingDto>
But if kept in alphabetical order - everything is there. Is this just a Fiddler thing? Or is this something I need to fix because of the easy solution I'm missing ;)
Upvotes: 0
Views: 938
Reputation: 3084
It is a requirement in WCF that unless you specify an order on the DataMember that member properties are sent in alphabetical order.
See the answer to this question resently
Not all parameters in WCF data contract make it through the web service call
More info can be found here
msdn.microsoft.com/en-us/library/ms729813.aspx
Thanks
Upvotes: 2