0

I am trying to set up a C# Web API that uses OData 4. I created an OdataController and believe I routed it correctly in the WebApiConfig. I put a debugger on each function in the controller to see if the request enters the method(s). When I hit GET http://localhost:10013/odata/Call the debugger in the first method hits but once I let the debugger move on the request fails. In Chrome I see the request returns with '406 Not Acceptable' but there is nothing in the preview or response tabs. What am I doing wrong? I can see that the request enters the controller correctly but why does it not return the string "call" as well as send a 406?

Secondly, if I send the request http://localhost:10013/odata/Call(0) the first method in the controller gets hit not the second (desired) or even the third. What am I doing wrong here if I want it to hit the second or third method?

I've included the controller and the WebApiConfig that I am using.

namespace JamesMadison
{
    public static class Call
    {
    }
}

using System.Web.Http.OData;

namespace JamesMadison.Controllers
{
    public class CallController : ODataController
    {
        public string GetCall()
        {
            return "call";
        }

        public string GetCall([FromODataUri] int id)
        {
            return "call";
        }

        public string GetCall([FromODataUri] string key)
        {
            return "call";
        }
    }
}

using System.Web.Http;
using System.Web.OData.Builder;
using System.Web.OData.Extensions;

namespace JamesMadison
{
    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            config.MapODataServiceRoute("odata", "odata", model: GetModel());    
        }

        public static Microsoft.OData.Edm.IEdmModel GetModel()
        {
            ODataModelBuilder builder = new ODataConventionModelBuilder();
            builder.EntitySet<Call>("Call");

            return builder.GetEdmModel();
        }
    }
}
James Madison
  • 337
  • 1
  • 4
  • 17
  • How did you generate your request? [406](http://stackoverflow.com/questions/14251851/what-is-406-not-acceptable-response-in-http) suggests you are missing headers. Did you see answers [here](http://stackoverflow.com/questions/29975653/odatacontroller-returning-http-406-not-acceptable) and [here](http://stackoverflow.com/questions/26676879/webapi-and-odatacontroller-return-406-not-acceptable)? – Jasen Dec 09 '16 at 17:41

1 Answers1

0

In the controller, I had using System.Web.Http.OData; and replaced it with using System.Web.OData;

James Madison
  • 337
  • 1
  • 4
  • 17