API routing error. Several actions were found that match the request with various API paths

I am implementing MVC web API in C #. Implementation of my snippet: - WebApiConfig.cs

config.Routes.MapHttpRoute(
   name: "getMultiProbe",
   routeTemplate: "api/v1/{controller}/probe/{server}"
);

config.Routes.MapHttpRoute(
   name: "getCurrentMultiProbe",
   routeTemplate: "api/v1/{controller}/currentmultiprobe/{server}"
);

And the controller associated with the methods that generate the problem: - HistController.cs

[HttpPost]
public Dictionary<string, List<DataSample>> getMultiProbe(string server, [FromBody] Dictionary<string,Object> request)
{       
    Debug.WriteLine("ENTER [GetMultiProbe] "+ request["from"] + " -   mode: " + request["mode"]);
    string[] tagnames = (string [])request["tagnames"];
    return null;        
}

[HttpPost]
public Dictionary<string, Object[]> getCurrentMultiProbe(string server, [FromBody] String[] tagnames)
{       
    Debug.WriteLine("ENTER [getCurrentMultiProbe] server: " + server + " - tagnames: " + tagnames);
    return null;
}

from client-client returns an error:

{ "": " .", "ExceptionMessage": " , : getMultiProbe HistService.Controllers.HistController getCurrentMultiProbe HistService.Controllers.HistController",      "ExceptionType": "System.InvalidOperationException",      "StackTrace": " System.Web.Http.Controllers.ApiControllerActionSelector.ActionSelectorCacheItem.SelectAction(HttpControllerContext controlContext) System.Web.Http.Controllers.ApiControllerActionSelector.SelectAction(HttpControllerContext controlContext) System.Web.Http.ApiController.ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancelationToken) System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()"     }

, /currentmultiprobe /probe. . , .

+5
2

OP , HTTP- (POST)

() defaults .

config.Routes.MapHttpRoute(
   name: "getMultiProbe",
   routeTemplate: "api/v1/{controller}/probe/{server}",
   defaults: { controller = "Hist", action = "getMultiProbe" }
);

config.Routes.MapHttpRoute(
   name: "getCurrentMultiProbe",
   routeTemplate: "api/v1/{controller}/currentmultiprobe/{server}",
   defaults: { controller = "Hist", action = "getCurrentMultiProbe" }
);
+5

{action}

config.Routes.MapHttpRoute(
       name: "ActionRoute",
       routeTemplate: "api/v1/{controller}/{action}/{server}"
    );

[HttpPost]
[ActionName("probe")]
public Dictionary<string, List<DataSample>> getMultiProbe(string server, [FromBody] Dictionary<string,Object> request)
{       
    Debug.WriteLine("ENTER [GetMultiProbe] "+ request["from"] + " -   mode: " + request["mode"]);
    string[] tagnames = (string [])request["tagnames"];
    return null;        
}

[HttpPost]
[ActionName("currentmultiprobe")]
public Dictionary<string, Object[]> getCurrentMultiProbe(string server, [FromBody] String[] tagnames)
{       
    Debug.WriteLine("ENTER [getCurrentMultiProbe] server: " + server + " - tagnames: " + tagnames);
    return null;
}
+2

Source: https://habr.com/ru/post/1669145/


All Articles