c# - OData routes return 404 Not Found -


i've started including odata in webapi2 project (currently hosted in iis8 express on dev machine). odata config class looks this:

public class odataconfig {     private readonly odataconventionmodelbuilder modelbuilder;      public odataconfig()     {         modelbuilder = new odataconventionmodelbuilder();          modelbuilder.entityset<category>("category");     }      public iedmmodel getedmmodel()     {         return modelbuilder.getedmmodel();     } } 

then added following in webapiconfig class:

odataconfig odataconfig = new odataconfig();  config.mapodataserviceroute(     routename: "odataroute",     routeprefix: "myserver/odata",     model: odataconfig.getedmmodel(),     defaulthandler: sessionhandler ); 

and started basic controller , 1 action, 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 httpclient, request url looks this: myserver/odata/category(10)

however, i'm getting following error:

{"message":"no http resource found matches request uri 'http://localhost/myserver/odata/category(10)'.","messagedetail":"no type found matches controller named 'odata'."} 

what missing here?

edit

if set routeprefix null or 'odata' , change request url accordingly, request works fine. means can't have route prefix 'myserver/odata'.

is odata standard naming convention? , if yes, can overridden?

i've been using same webapiconfig.register() method included default in web api project , passing using following:

var builder = new odataconventionmodelbuilder();  // odata entity sets.. builder.entityset<seat>("seats"); builder.entityset<table>("tables");  // configure route config.routes.mapodataserviceroute("odata", "odata", builder.getedmmodel()); 

the first parameter friendly name, second 1 you're after! can change whatever want.

update: if you're using odata v4, routing initialised this:

config.mapodataserviceroute("odata", "odata", builder.getedmmodel());

if you're using v4, method based routing via use of attributes available (think nancy style)

you can use in either owin startup class or global.asax. either way works fine me.

refer: http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-v3/creating-an-odata-endpoint


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -