i new web api. have implemented web service methods [.asmx] using deprecated webservices - attributes [webmethod] , able place different methods in .asmx file , able call them webmethod name in ajax calls.
i trying move webapi, , dont see use different methods here in webapi.
for ex., in webservice.asmx file, declare :
[webmethod] public void loadreport() { ... } [webmethod] public void loadreport2() { ... }
but in webapi, utilize get(), put(), post() , delete().
how declare these 2 different methods in web api ?
use attribute routing in web api.
for example:
[routeprefix("api/data")] public class datacontroller : apicontroller { [route("loadreport")] [httpget] public httpresponsemessage loadreport() { ... } [route("loadreport2")] [httpget] public httpresponsemessage loadreport2() { ... }
you can access these methods calling
http://localhost:<port>/api/sample/loadreport http://localhost:<port>/api/sample/loadreport2
if use .net 4.5.2, ensure attribute routing enabled. add below line under register
method of app_start\webapiconfig.cs file:
public static void register(httpconfiguration config) { config.maphttpattributeroutes(); //enable attribute routing
Comments
Post a Comment