나는 다음과 같은 코드를 가지고 있지만, 요청 종료 (푸()/바()) 내 WebApiConfig에서 사용자 지정 경로를했습니다ASP.NET WebAPI은 - 조치를 찾을 수 없습니다
No action was found on the controller 'Device' that matches the request.
항상 :
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new {id = RouteParameter.Optional}
);
내 ASP.NET WebAPI 컨트롤러 :
[HttpPost]
public void UpdateToken(string newToken)
{
_deviceHandler.UpdateToken(newToken);
}
내가 RestSharp을 사용하고 내 ASP.NET의 WebAPI를 조회합니다.
private static void Send(string resource, Method method, object payload)
{
var client = new RestClient(baseUrl);
var request = new RestRequest(resource, method);
request.XmlSerializer = new JsonSerializer();
request.RequestFormat = DataFormat.Json;
request.AddBody(payload);
var response = client.Execute(request);
// ... handling response (exceptions, errors, ...)
}
public void Foo()
{
var newToken = "1234567890";
Send("/api/device/updatetoken", RestSharp.Method.POST, newToken);
}
public void Bar()
{
var newToken = new { newToken = "1234567890" };
Send("/api/device/updatetoken", RestSharp.Method.POST, newToken);
}
이 오류를 방지 할 수있는 유일한 방법은
속성 래퍼 클래스를 생성한다 (얻는다; 집합) 그것을하는 제어기 인수 (newToken)의 이름을 갖는다.하나 또는 두 개의 사용자 정의 문자열 (정의되지 않은 길이)을 게시물 (get 길이가 제한됨)로 보내는 많은 요청이 있습니다. 그러나 각 시나리오를 작성하기 위해서는 래퍼 구현이 실제 오버 헤드입니다! 나는 다른 길을 찾고 있습니다.
PS : 나는
감사합니다. [FromBody]가 누락되었습니다. 감사합니다. – dannyyy
이것은 내 밤을 구했다. 나는이 특정 루트가 404를 얻는 이유에 대해 궁금해했다. 나머지 루트가 참조 유형을 취하는 곳에서 int를 사용한다. [FromBody] 속성을 추가하는 것이 트릭을 만들었습니다. – squillman
내 인생의 반나절을 절약하기 위해 1, 절반은 이미 그것에 낭비 감사합니다 –