I've started including OData in my WebAPi2 project (currently hosted in IIS8 Express on my dev machine). My OData config class looks like this:
public class ODataConfig
{
private readonly ODataConventionModelBuilder modelBuilder;
public ODataConfig()
{
modelBuilder = new ODataConventionModelBuilder();
modelBuilder.EntitySet<Category>("Category");
}
public IEdmModel GetEdmModel()
{
return modelBuilder.GetEdmModel();
}
}
Then I added the following in my WebApiConfig class:
ODataConfig odataConfig = new ODataConfig();
config.MapODataServiceRoute(
routeName: "ODataRoute",
routePrefix: "MyServer/OData",
model: odataConfig.GetEdmModel(),
defaultHandler: sessionHandler
);
And started with a basic controller and just one action, like this:
public class CategoryController : ODataController
{
[HttpGet]
public IHttpActionResult Get([FromODataUri] int key)
{
var entity = categoryService.Get(key);
if (entity == null)
return NotFound();
return Ok(entity);
}
}
Then, in my HttpClient, the request url looks like this: MyServer/OData/Category(10)
However, I'm getting the following error:
{"Message":"No HTTP resource was found that matches the request URI 'http://localhost/MyServer/OData/Category(10)'.","MessageDetail":"No type was found that matches the controller named 'OData'."}
What am I missing here?
EDIT
If I set the routePrefix to null or 'odata' and change my request url accordingly, the request works fine. So this means that I can't have a route prefix like 'myServer/odata'.
Is this OData standard naming convention? And if yes, can it be overridden?