I’ve countered a very strange problem with my web service that I’m building with MVC4 / WebAPI.
Basically, I have one method called ‘GetChildNodes’ which, when I request it, gives me a 405: Method Not Allowed status code. If I rename this to ‘Test’, it works. If I rename it to ‘GCN’, it works. If I rename it to ‘GetChildNode’, I get the same error.
I’ve checked and double checked and each attempt, successful and unsuccessful, were requested properly but with varying results. I’m at a total loss as to how the method name can make any difference. I’ve tried restarts, reboots, it makes no difference.
Any clues would be appreciated!
If it helps, this is how I’m configuring the service:
config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{action}");
Fairly standard, I think.
Urgh, it was the prefix – ‘Get’ – which seems to tell WebAPI that the action is called from a GET request. Easily remedied by adding the ‘HttpPost’ (in System.Web.Http) attribute to the method.