I'm trying to create an owin self host webapi with odata support. I added all the dependencies and set everything up, when i call the get method (just by surfing to it with chrome). The breakpoint i put on the GET gets called and returns without an exception. But chrome just returns a blank screen, no http errors are found in the console of chrome. When i do this in IE10 (yes old version, but i am not allowed to update it) i get 406 (Not Acceptable).
This is my Startup.cs code :
public void Configuration(IAppBuilder appBuilder)
{
// Configure Web API for self-host.
HttpConfiguration config = new HttpConfiguration();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
//config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/json"));
//config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/xml"));
ODataModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<Product>("Products");
config.MapODataServiceRoute(
routeName: "ODataRoute",
routePrefix: null,
model: builder.GetEdmModel());
appBuilder.UseWebApi(config);
}
This is my controller code, just a simple GET.
public class ProductsController : ODataController
{
ProductsContext db = new ProductsContext();
[EnableQuery]
public IQueryable<Product> Get()
{
try
{
return db.Products;
}
catch (System.Exception ex)
{
string x = "y";
return db.Products;
}
}
}
db.Products is an empty table for now, but this should still return an empty array right ?
Any help is greatly appreciated! Thanks.