WebAPI 응용 프로그램의 개념 증명 프로토 타입을 작성하고 있으며 모든 일반적인 방법이 훌륭하게 작동합니다. 그러나 WebAPI를 통해 사용자 지정 메서드를 호출 할 수 있음을 보여주고 싶었습니다. 내 메소드를 호출하려고 시도WebAPI에서 호출하는 사용자 정의 메서드
[HttpGet]
public string Test()
{
return "this is a string";
}
: http://localhost:43225/api/values/test
난에서 오류를 다음 얻을 나는 간단한 방법이 컨트롤러에서
routes.MapHttpRoute(
name: "ActionApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
: 그래서 다음 내 RouteConfig.cs에서 라우팅이 브라 우어 :
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">
The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.String Get(Int32)' in 'WebAPI_Listener.Controllers.ValuesController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
</string>
하지만 그것은 작동 등 http://localhost:43225/api/values/test/1
로 URL의 끝에 ID를 지정하면, 방법 자체가 파를하지 않는 경우에도 ameter 전혀.
그래서 라우팅에서 {id}를 지정하지 않으면 {id}를 지정하지 않아도 {id}를 지정하지 않으면 작동하지만 작동하지 않는 이유는 메소드 자체가 ' {id}를 기대하고 있니?