for my WebAPI OData application, I am trying to give my client (browser) a decision in what format the data output should be. since $ format is not yet implemented in WebAPI OData, im using the Raghuramn example: https://gist.github.com/raghuramn/5556691
var queryParams = request.GetQueryNameValuePairs(); var dollarFormat = queryParams.Where(kvp => kvp.Key == "$format").Select(kvp => kvp.Value).FirstOrDefault(); if (dollarFormat != null) { request.Headers.Accept.Clear(); request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse(dollarFormat));
This works for JSON ($ format = application / json; odata = fullmetadata) and JSON light (format = application / json; odata = light), but not for xml yet.
if I add $ format = application / XML to the query string, it still produces json. how to force xml output?
EDIT:
even if I force xml to Fiddler by sending Content-type: application / xml and Accept: application / xml with the request, the answer simply lists: Content-Type: application / json; OData = minimalmetadata; streaming = TRUE; encoding = UTF-8
EDIT 2:
Accept: application / atom + xml seems to output xml in the original answer. Unfortunately, "application / atom + xml" throws a FormatException in:
request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/atom+xml"));
source share