Goodday All
I am using web API and am quite bit new in this. I ve a trouble in a routing problem. I have a controller with following actions
public class IndividualController : ApiController { static readonly IIndividualRepository repository = new IndividualRepository(); [AllowAnonymous] [ResponseType(typeof(Individual))] [HttpGet] public IEnumerable<Individual> GetIndividual(string Ind)// { return repository.Get(Ind); } [HttpGet] public IEnumerable<Individual> GetTCC(string TCCNo)// { return repository.GetTCC(TCCNo); } [HttpGet] public IEnumerable<Individual> GetAllIndividual() { return repository.GetAll(); }
}
public static class WebApiConfig { public static void Register(HttpConfiguration config) { // Web API configuration and services // Web API routes config.MapHttpAttributeRoutes(); // config.Routes.MapHttpRoute( // name: "WithActionApi", // routeTemplate: "api/{controller}/{action}/{Ind}" // ); // config.Routes.MapHttpRoute( // name: "WithActionApi2", // routeTemplate: "api/{controller}/{action}/{TCCNo}" //); config.Routes.MapHttpRoute("DefaultApiWithId", "Api/{controller}/{Ind}", new { Ind = RouteParameter.Optional }, new { Ind = @"\d+" }); config.Routes.MapHttpRoute("DefaultApiWithAction", "Api/{controller}/{action}"); config.Routes.MapHttpRoute("DefaultApiGet", "Api/{controller}", new { action = "Get" }, new { httpMethod = new HttpMethodConstraint(HttpMethod.Get) }); config.Routes.MapHttpRoute("DefaultApiGet1", "Api/{controller}", new { action = "GetTCC" }, new { httpMethod = new HttpMethodConstraint(HttpMethod.Get) }); config.Routes.MapHttpRoute("DefaultApiPost", "Api/{controller}", new { action = "Post" }, new { httpMethod = new HttpMethodConstraint(HttpMethod.Post) }); // config.Formatters.XmlFormatter. config.Formatters.JsonFormatter. SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html")); } }
The problem occur when i added this action GetTCC given this error Multiple actions were found that match request.
Please can any help to solve this problem. It actually works when GetTCC was not included in the controller with the commented section of the routes used.
But the point now is that i needed to have this two Method Get and GetTCC in a single controller.
Thank You