i made own web api , i'm trying make work. code app_start > webapiconfig.cs
:
public static void register(httpconfiguration config) { // web api routes config.maphttpattributeroutes(); config.routes.maphttproute( name: "defaultapi", routetemplate: "api/{controller}/{action}" ); }
this controller:
public class messagescontroller : apicontroller { public string getmessages() { return messagesservice.get(); } }
i've tried debuggon on line return messagesservice.get();
, doesn't came far..
i have feeling i'm missing references, because made these classes empty templates.
your solution should similar to:
project project > web.config project > global.asax.cs project > app_start > webapiconfig.cs project > controllers > messagescontroller.cs
for more info on global.asax.cs should please see: this link
also, since controller action defined type, go messages method name instead of getmessages()
what may creating new web project in visual studio , choose web api project type. understand basic structure of web api project.
edit
public class webapiapplication : system.web.httpapplication { protected void application_start() { globalconfiguration.configure(webapiconfig.register); } }
here sample of global.asax file web api.
to add new file:
in visual studio 2013
open solution explorer. right-click on project. add new item. vb or c# web. general. global application class.
Comments
Post a Comment