0

I have an API controller and GET method like this :

public IEnumerable<CountryDTO> GetContries(string sortOrder, string searchString)
{
    return countryRepository.GetCos(sortOrder,  searchString);
}

but when I try to get url api/countries I`ve got an error like: The requested resource does not support http method 'GET'.

How to fix this problem?

ekad
  • 14,436
  • 26
  • 44
  • 46
MR. m
  • 11
  • 4
  • Does this answer it? http://stackoverflow.com/questions/12765636/the-requested-resource-does-not-support-http-method-get – Lukos Aug 15 '16 at 10:22
  • Unfortunately ,no( – MR. m Aug 15 '16 at 10:33
  • [System.Web.Http.AcceptVerbs("GET")] [System.Web.Http.HttpGet] public IEnumerable GetContries(string sortOrder, string searchString) { return countryRepository.GetCos(sortOrder, searchString); } – MR. m Aug 15 '16 at 10:39
  • and web config: config.Routes.MapHttpRoute( name: "CountryRoute", routeTemplate: "api/country;{sortOrder};{searchString}", defaults: new { controller = "Country", action = "GetContries", sortOrder = RouteParameter.Optional, searchString = RouteParameter.Optional }, constraints: new { httpMethod = new HttpMethodConstraint(HttpMethod.Get) } – MR. m Aug 15 '16 at 10:40

1 Answers1

0

Try to explicitly mark the method [HttpGet] and make the following change to your method.

[HttpGet]    
public IEnumerable GetCountries(string sortOrder, string searchString)
{
   return countryRepository.GetCos(sortOrder, searchString).ToList();
}

Also, I would recommend before you make the change, simply test your method using a tool like SOAPUI or Fiddler. See if you are able to get a response. That way you know for sure that problem is not in the basics of the method formation.

[HttpGet]    
public string GetCountries(string sortOrder, string searchString)
{
   return ("returns list of countries");
}
Mihir Kale
  • 1,028
  • 1
  • 12
  • 20