Excel connection exception with .Net Core v1.1 OData v4 Add at least one media type?

Using .Net Core v1.1to create a service OData, it works fine with the browser, although it does not work when connecting from Excel 2016, as the main ODatafeed. The exception is

'InvalidOperationException' Media types not found in "Microsoft.AspNetCore.OData.Formatter.ODataOutputFormatter.SupportedMediaTypes". Add at least one media type to the list of supported media types.

Both Excel and browser connect to http: // localhost: 52315 / odata using the = 'GET method

HeaderAccept from browser:

"text/html, application/xhtml+xml, image/jxr, */*"

HeaderAccept from excel: (NOTE: I added new lines after ';' for reading)

"application/json;
odata.metadata=minimal;
q=1.0,application/json;
odata=minimalmetadata;
q=0.9,application/atomsvc+xml;
q=0.8,application/atom+xml;
q=0.8,application/xml;
q=0.7,text/plain;
q=0.7"

, , . , , .

+4
1

, -, (cf https://github.com/OData/WebApi/issues/597). , vNext, , , .

Startup.cs, Odata, :

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();
    services.AddOData();
    services.AddMvcCore(options =>
    {
        // loop on each OData formatter to find the one without a supported media type
        foreach (var outputFormatter in options.OutputFormatters.OfType<ODataOutputFormatter>().Where(_ => _.SupportedMediaTypes.Count == 0))
        {
            // to comply with the media type specifications, I'm using the prs prefix, for personal usage
            outputFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/prs.dummy-odata"));
        }
    });
}

, , .

:

+1

Source: https://habr.com/ru/post/1669548/


All Articles