I started incorporating OData into my WebAPi2 project (currently hosted in IIS8 Express on my dev machine). My OData configuration class is as follows:
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 to my WebApiConfig class:
ODataConfig odataConfig = new ODataConfig(); config.MapODataServiceRoute( routeName: "ODataRoute", routePrefix: "MyServer/OData", model: odataConfig.GetEdmModel(), defaultHandler: sessionHandler );
And it started with a basic controller and just one action, for example:
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 get 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 routePrefix to null or 'odata' and change the request URL accordingly, the request works fine. So this means that I cannot have a route prefix like "myServer / odata".
Is this the standard OData naming convention? And if so, can this be overridden?
c # odata asp.net-web-api
Ivan-Mark Debono
source share