Search code examples
asp.net-web-apiodata

Web API 2 OData = $format not working: the request is always ignored


I have a Web API OData project and everything is working great. I'm now trying to return xml instead of JSON using the $format parameter, as opposed to specifying a header request, and it is not working. I've tried these approaches:

http://localhost:3845/api/Customer?$format=application/xml
http://localhost:3845/api/Customer?$format=xml
http://localhost:3845/api/Customer?$format=application/xml;odata.metadata=full

All without success. This article says that it is possible: https://blogs.msdn.microsoft.com/webdev/2014/03/13/getting-started-with-asp-net-web-api-2-2-for-odata-v4-0/

I have updated all of my NuGet packages, but it seems that the request is always ignored, and instead I get JSON every time.


Solution

  • Since the ATOM format (XML) is only a technical committee specification instead of an OASIS standard for the OData V4 protocol, the ATOM format is disabled in the ODataLib from the version 6.3.0.

    The correct way to ask the OData V4 service to respond in XML is as follows:

    GET http://localhost:3845/api/Customer?$format=application/atom+xml
    

    or set the header Accept to application/atom+xml. But due to the reason mentioned above, it doesn't work for Web API OData V4.