0

I have ASP.NET WebAPI project, which has Get API - "appointment/available" defined as follows:

using System;
using System.Web.Http;
using AppointmentScheduler;
using Microsoft.Practices.Unity;

[RoutePrefix("appointment")]
public class AppointmentController : ApiController
{
    #region [ Properties ]
    [Dependency]
    public IAppointmentScheduler AppointmentScheduler { get; set; }
    #endregion

    #region [ Methods - API ]
    [Route("available")]
    [HttpGet]
    public IHttpActionResult GetAvailableAppointments(string agentEmailId, DateTime startDate, DateTime endDate) {
        try {
            return base.Ok(this.AppointmentScheduler.GetAppointments(agentEmailId, startDate, endDate));
        } catch (Exception exception) {
            return base.InternalServerError(exception);
        }
    }

    #endregion
}

However, on running the solution and calling the API from Fiddler as "GET" request I get following error:

HTTP 405 Error - The requested resource does not support http method 'GET'.

On sending the same request as "POST" I get HTTP - 200 response. Even though my method was never called (the breakpoint on the API method was never hit)

I looked into previous query on this issue here. But none of the answers seems to be solve my issue.

Interestingly, unless I'm crazy the exact code was working for me sometime back.

I think the issue started coming up when I tried to open the solution initially built on VS 2013 on VS 2015. I feel, only after that the solution started giving issue in both the IDEs.

Community
  • 1
  • 1
Ankit Vijay
  • 3,752
  • 4
  • 30
  • 53

1 Answers1

0

It turned out that I was calling a API with wrong url - Instead of calling "appointment/available", I was calling "api/appointment/available" by mistake. Ended up wasting my morning on a non-issue.

However, one thing which I still could not understand it why it returned Http Status 405 for "Get" request and 200 for "Post" and NOT "404" when the API did not exist.

Update:

Got the issue, there was one more method in the same controller.

    [HttpPost]
    public IHttpActionResult BlockAppointment(Appointment appointment) {
        try {
            return base.Ok(this.AppointmentScheduler.BlockAppointment(appointment));
        } catch (Exception exception) {
            return base.InternalServerError(exception);
        }
    }

This API call for above method was: POST api/appointment. So, I was actually calling above method and not the indented method from Fiddler and never realized that.

Ankit Vijay
  • 3,752
  • 4
  • 30
  • 53