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();
}
}
}