jeudi 30 avril 2015

406 error with OData service in Visual studio

I have spent the past 6 hours trying to figure out why my odata service doesn't work to no avail. I keep getting a 406 error and I have tried all recommended solutions to no avail. Please help. Below is my code.

public class Person
{
    public int Id { get; set; }
}

public class TestController : ODataController
{

[EnableQuery]
public IQueryable<Person> GetTest()
{
        try
        {
            var persons = new List<Person>(){new Person{ Id= 1}};
            return persons.AsQueryable();
        }
        catch (Exception ex)
        {
            var here = "dd";
        }
        return null;
    }

In my webapiconfig class, I have: // Web API routes config.MapHttpAttributeRoutes();

        var builder = new ODataConventionModelBuilder();
                 builder.EntitySet<Person>("Person"); 
        config.MapODataServiceRoute("odata", "odata", builder.GetEdmModel());

        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );

        config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;

It keeps failing with 406 error. It hits the breakpoint in my controller, but does not return the data. Thanks




Aucun commentaire:

Enregistrer un commentaire