Why is it possible to send in a WCF DataService the following JSON string:
{ SomeElement: 'val1', SomeOtherElement: 'val2' }
whilest you have to send in an normal WCF Service like
[OperationContract,
WebInvoke (Method = "POST",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyl开发者_StackOverflow社区e.Wrapped)]
public string SomeMehtod(string SomeElement, string SomeOtherElement)
the following JSON string
{ "SomeElement": "val1", "SomeOtherElement": "val2" }
This inconsistency is not clear to me. Why do I have to use double quotes in the normal web serive whilest I can omit the quotes for the element name in WCF data services?
Maybe somone knows an answer to this....
I am very familiar with the internal plumbing behind WCF's JSON parsing infrastructure, and essentially, the plumbing that takes care of the second situation is really designed to support "strict" standards-complaint JSON.
It's just a coincidence that the first situation works with non-compliant JSON. Don't read into it. It was not a conscious design decision. Hope this clears up confusion!
For more details, you can just explore DataContractJsonSerializerOperationFormatter, DataContractJsonSerializerOperationBehavior, and DataContractJsonSerializer using Reflector.
精彩评论