0
votes

I am testing a Web API project using OData and EF to return results form a SQL Server view. It took a while but I finally got it working. What I'd like to do next is use a different formatter to return the results.

According to this link I should have options for atom, json, and xml using the $format parm. But this parm appears to be ignored. Digging some more I found articles similar to this one that say you have to add commands to allow the $format parm to work but I have no reference to "Configuration.Formatters.XmlFormatter.AddQueryStringMapping" which I've found in several other articles. I have seen references to testing with Fiddler and the updating to return JSON for example but I want to use $format so I can also pull different formats in SSIS.

The closest thing I find is this post but there is no solution for XML besides Fiddler and the JSON $format commands do not work for me. I assume that maybe things changed in the past 4 months.

Is there anyway to get $format to work with XML?

2
I'm not sure I want to mark this as a solution yet but one really horrible way to make this work was to remove JSON as an option. In the WebApConfig I am able to add the command config.Formatters.Remove(config.Formatters.JsonFormatter) and this takes JSON off as the default and returns XML. But, like I said, this seems like a poor solution. - pretzelb
according to this SO answer if you're using OData v4 - you cannot do it at all - but pls post back if you do figure it out. - bkwdesign

2 Answers

0
votes

AddQueryStringMapping is an extension method in class: System.Net.Http.Formatting.MediaTypeFormatterExtensions

If that doesn't work, you can follow the example https://gist.github.com/raghuramn/5556691 to always set the request accept header with application/xml or application/atom+xml.

Please let me know if you have any other question.

0
votes

I am going to say this is a problem with the VB.Net version of the code. It seems to work fine if you switch to C#.