私はWeb API MVCをC#で実装しています。私のスニペットの実装は次のとおりです。 - WebApiConfig.csWEB APIルーティングエラー異なるAPIパスで要求に一致する複数のアクションが見つかりました
config.Routes.MapHttpRoute(
name: "getMultiProbe",
routeTemplate: "api/v1/{controller}/probe/{server}"
);
config.Routes.MapHttpRoute(
name: "getCurrentMultiProbe",
routeTemplate: "api/v1/{controller}/currentmultiprobe/{server}"
);
、問題を発生させる方法に関連したコントローラは、以下のとおりです。 - 残りのクライアントから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;
}
はエラーを返します。
{"Message": "An error has occurred.","ExceptionMessage": "Multiple actions were found that match the request: getMultiProbe on type HistService.Controllers.HistController getCurrentMultiProbe on type HistService.Controllers.HistController", "ExceptionType": "System.InvalidOperationException", "StackTrace": " at System.Web.Http.Controllers.ApiControllerActionSelector.ActionSelectorCacheItem.SelectAction(HttpControllerContext controllerContext) at System.Web.Http.Controllers.ApiControllerActionSelector.SelectAction(HttpControllerContext controllerContext) at System.Web.Http.ApiController.ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken) at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()" }
/currentmultiprobeと/ probeのパスが異なるため、異なるパスに一致させる必要はありません。パスとサービスの間で名前入力パラメータを変更しようとしました。この設定を行う方法があるかどうか尋ねます。
であなたのコントローラで使用することができ、これは、他のコントローラにマップしようとしていますか?そうでない場合は、デフォルトを使用して範囲を絞り込みます。 – Nkosi