I am currently also experimenting with OData support using the beta package associated with you. We must keep in mind that this is a beta package and everything may change before release. I ran into the same problem. Right now, it looks like Microsoft is planning to provide OData v3 support in Web Api by looking at ODataMediaTypeFormatter.
There will be three formats in OData v3:
- Atom (
application/atom+xml ) - JSON Verbose (
application/json;odata=verbose ) - JSON Light (
application/json;odata=light )
Atom is the only and therefore default XML OData format. The default JSON format in OData v3 is the JSON indicator. The old OData v2 JSON format is what became Verbose JSON in OData v3.
This is supported by Spec (v20120705), section 2.2.5.1, which lists Accept and the corresponding response headers:
application / json; odata = verbose β οΏΌ application / json; odata = verbose
application / json; odata = light οΏΌ β application / json; odata = light
application / json β For answers of version 1.0 and version 2.0: application / json; odata = verbose. For version 3.0 responses: application / json; odata = light
Unfortunately, they have not yet indicated JSON light (section 2.2.5.1.3, my emphasis):
The JSON light format is a new format defined only in the OData 3.0 protocol, which is optimized for small sizes, not including metadata information in views. The verbose format is the existing JSON format defined by the OData 1.0, 2.0, and 3.0 protocol, which includes metadata information along with an instance view. The JSON content-type highlight format is not defined by this version of the document .
I expect, however, that the JSON Light format will be the correct subset of the JSON Verbose format. The current implementation of ODataMediaTypeFormatter will only respond to application/json;odata=verbose and application/atom+xml headers, or return to ATOM. Interestingly, as indicated, $format=json returns 406 .
If you want a workaround that assumes a light format to be the correct subset of the detailed format, you can tell MediaTypeFormatter to respond to application/json requests, which greatly facilitates working with OData from jQuery, because we may not specify an accept header:
ODataMediaTypeFormatter odataFormatter = new ODataMediaTypeFormatter(model); odataFormatter.SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("application/json"));