c# - How to change route in WebApi+Odata project -
i'm re-implementing wcf service , choose use webapi 2.2 + odata v4. problem i'm facing need have route contains '_' , i'm unable implement it. have this:
public class annotationsharedwithcontroller : odatacontroller { ... [enablequery] public iqueryable<annotationsharedwith> get() { return _unitofwork.annotationsharedwith.get(); } ... }
and webapiconfig.cs looks this:
public static void register(httpconfiguration config) { config.mapodataserviceroute("webservice",null,generateedmmodel()); config.count(); } private static iedmmodel generateedmmodel() { var builder = new odataconventionmodelbuilder(); builder.entityset<annotationsharedwith>("annotation_shared_with"); return builder.getedmmodel(); }
when issue request receive following error
{ "message": "no http resource found matches request uri 'http://localhost:12854/annotation_shared_with'.", "messagedetail": "no type found matches controller named 'annotation_shared_with'." }
by default odata search annotation_shared_withcontroller
defined in edm model. since controller named annotationsharedwithcontroller
return 404
.
renamaing controller class solve issue. end messy class names.
you can implement own routing conventions, see routing conventions in asp.net web api 2 odata more details
hope helps.
Comments
Post a Comment