This project is read-only.


application/json should return json verbose when MaxDataServiceVersion is 2.0


We should return json verbose payload when old client requests for json. This is the same behavior as WCF DS.

Currently, we always returns json light payload and fails when MaxODataServiceVersion is lower than 3.0.

The fix is to make CanWriteType smarter about DataServiceVersion, or won't fix it as we are only V3.0 service.
Closed Oct 3, 2013 at 11:26 PM by danroth27
We don't support OData v2.0.


HongmeiG wrote Feb 4, 2013 at 10:33 PM

The OData lib does not like the DataServiceVersion = 2.0 as it does not support the fullmetadata with 2.0.

Here is the exception message
  • $exception "A supported MIME type could not be found that matches the acceptable MIME types for the request. The supported type(s) 'application/atom+xml;type=feed, application/atom+xml, application/json;odata=verbose, application/json' do not match any of the acceptable MIME types 'application/json; odata=fullmetadata; charset=utf-8'." System.Exception {Microsoft.Data.OData.ODataContentTypeException}
Here is the stack
System.Web.Http.OData.dll!System.Web.Http.OData.Formatter.Serialization.ODataFeedSerializer.WriteObject(object graph, Microsoft.Data.OData.ODataMessageWriter messageWriter, System.Web.Http.OData.Formatter.Serialization.ODataSerializerContext writeContext) Line 61 + 0x11 bytes C#
System.Web.Http.OData.dll!System.Web.Http.OData.Formatter.ODataMediaTypeFormatter.WriteToStreamAsync.AnonymousMethod__9() Line 425 + 0x2f bytes C#
System.Web.Http.OData.dll!System.Threading.Tasks.TaskHelpers.RunSynchronously(System.Action action, System.Threading.CancellationToken token) Line 208  C#
System.Web.Http.OData.dll!System.Web.Http.OData.Formatter.ODataMediaTypeFormatter.WriteToStreamAsync(System.Type type, object value, System.IO.Stream writeStream, System.Net.Http.HttpContent content, System.Net.TransportContext transportContext) Line 339 + 0x33 bytes C#
System.Net.Http.Formatting.dll!System.Net.Http.ObjectContent.SerializeToStreamAsync(System.IO.Stream stream, System.Net.TransportContext context) Line 112 + 0x3a bytes C#
System.Net.Http.dll!System.Net.Http.HttpContent.CopyToAsync(System.IO.Stream stream, System.Net.TransportContext context) Line 223 + 0xf bytes  C#
System.Net.Http.dll!System.Net.Http.HttpContent.CopyToAsync(System.IO.Stream stream) Line 259 + 0x7 bytes   C#
System.Web.Http.SelfHost.dll!System.Web.Http.SelfHost.Channels.HttpMessageEncoderFactory.HttpMessageEncoder.WriteMessage(System.ServiceModel.Channels.Message message, System.IO.Stream stream) + 0x13b bytes   
System.Web.Http.SelfHost.dll!System.Web.Http.SelfHost.Channels.HttpMessageEncoderFactory.HttpMessageEncoder.WriteMessage(System.ServiceModel.Channels.Message message, int maxMessageSize, System.ServiceModel.Channels.BufferManager bufferManager, int messageOffset) + 0x266 bytes   

mdesousa wrote May 29, 2013 at 6:53 PM

We are seeing a similar issue, except that we just get a generic error message. This request was issued by Pebble Reports. The problem goes away if I issue the same request from Fiddler, without the MaxDataServiceVersion header.

User-Agent: Microsoft ADO.NET Data Services
MaxDataServiceVersion: 2.0;NetFx
SL-User-Agent: OData Reporting
Accept: application/atom+xml,application/xml
Accept-Charset: UTF-8

<?xml version="1.0" encoding="utf-8"?>
<m:error xmlns:m="">
<m:code />
<m:message xml:lang="en-US">An error has occurred.</m:message>

mitchellb wrote Dec 31, 2014 at 10:03 PM

I came across this issue today when trying to work with SAPUI5/OpenUI5. These web frameworks "require" an OData v2 endpoint (experimental with anything else). If you want to use Web API OData, you need to read off the MaxDataServiceVersion by attaching to a message handler.

In your WebApiConfig Register method, add a handler to your new v2 support class.
config.MessageHandlers.Add(new ODatav2SupportHandler());
In this ODatav2SupportHandler class, add the following,
using System;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Web.Http.Hosting;

namespace OData_v3_Demo.Helpers
    /// <summary>
    /// Built with assistance from
    /// <para>
    /// Checks compatibility against MaxDataServiceVersion per OData v3 Spec
    /// </para>
    /// </summary>
    public class ODatav2SupportHandler : DelegatingHandler
        private readonly string jsonMediaType = "application/json";
        private readonly string verboseJsonMediaType = "application/json;odata=verbose"; // creates OData v2 parseable response
        private readonly string maxDataServiceVersionHeaderKey = "MaxDataServiceVersion";
        private readonly string formatQueryParameterKey = "$format";
        private readonly string dataServiceVersionODataV2 = "2.0";

        protected override System.Threading.Tasks.Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
            var queryParams = request.GetQueryNameValuePairs();
            var dollarFormat = queryParams.Where(kvp => kvp.Key == formatQueryParameterKey).Select(kvp => kvp.Value).FirstOrDefault();
            var maxDataServiceVersionHeader = request.Headers.Where(h => h.Key == maxDataServiceVersionHeaderKey).Select(h => h.Value).FirstOrDefault();
            string maxDataServiceVersion = null;

            if (maxDataServiceVersionHeader != null)
                maxDataServiceVersion = maxDataServiceVersionHeader.ElementAtOrDefault(0);

            if (dollarFormat != null)
                catch (FormatException fe)
                    // log invalid format request
                    System.Diagnostics.Debug.WriteLine(string.Format("Error adding $format Accept header '{0}': {1}", dollarFormat, fe.Message));
                    request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse(verboseJsonMediaType)); // fallback on verbose JSON

                // remove $format from the request
                request.Properties[HttpPropertyKeys.RequestQueryNameValuePairsKey] = queryParams.Where(kvp => kvp.Key != formatQueryParameterKey);
                if (maxDataServiceVersion == dataServiceVersionODataV2 &&
                    request.Headers.Accept.FirstOrDefault().MediaType == jsonMediaType)

            return base.SendAsync(request, cancellationToken);
Then, any requests with MaxDataServiceVersion == 2.0 asking for application/json will be properly sent the verbose JSON result. I had to do more things like allowing $count and fixing CORS issues, but this should help anyone that comes by looking for help.

As an added bonus, above should help support $format requests.

mitchellb wrote Dec 31, 2014 at 10:07 PM

I've added the above to a Gist itself.