I have a pair of apps I'm testing; one is an ASP.NET Web API app (.NET 4.5.1); I have several RESTful methods that I call from a .NET 3.5 C# desktop app. The first two RESTful methods I tested are working fine; the code is identical for all of the RESTful methods, except the queries used to load the data in the Repository's constructor.
I have log4net set up in the server / Web API app. Well into the reading of the records in the server in a while loop (record #270, to be precise), the server hits the end of the while loop (no more records), and never enters the catch block, but then the client shows the
"The remote server returned an error: (405) Method Not Allowed"
error dialog and no data is returned.
So the server/Web API seems to work fine, stepping through it, but something is obviously amiss. There is no log4net entry being saved from the server, although I've got this set up for such in the catch block:
catch (Exception ex)
{
log.Error(ex.Message);
}
(and I do have some entries in the log4net log file for previous exceptions, so it's working/set up right).
Stepping through the code in the client, this is the line it fails on:
var webResponse = (HttpWebResponse)webRequest.GetResponse();
Again, this is exactly the same code as used for the other, working, methods. What could be the real meaning of this vague "The remote server returned an error: (405) Method Not Allowed" communique? It is the client's catch block that is throwing/showing that exception, but where is it coming from? It seems like it's from between the Web API app and the client app - could it be emanating from IIS?
Can you check check the http verbs used on both sides is same. Usually 405 is returned when server expects POST but request tries to do a GET. Also posting your controller code and code used to consume the service would help.