SQL DB with webapi The requested resource does not support http method 'GET' RRS feed

  • Question

  • User368427 posted

    Storytime: So, im currently implementing my Azure SQL DB with my Xamarin android app, however ive hit a roadblock as i cant post directly to the database from android(from my console project i can read/write to it just fine so its not a problem with the database setup). I then created a simple web api to handle the database calls as suggested by others, by following this guide: https://www.c-sharpcorner.com/article/xamarin-android-create-login-with-web-api-using-azure-sql-server-part-one/ I got the login/get part to work, but when i try to post data to the database trough the web api, it returns the following error: " The requested resource does not support http method 'GET'" which is strange since its a post method. After doing some debugging, i found out that its in the apis database.SaveChanges(); call that breaks the code, but i dont know how to fix it. Ive done alot of reading around and used Postman to test

    My questions: Anyone else who have had succes following this guide? What can i have done wrong since its trying to convert my Post method into a get method?

    Thanks in advance for any tip or input you might have!

    // My routing configuration public static class WebApiConfig { public static void Register(HttpConfiguration config) { // Web API configuration and services

            // Web API routes
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            var json = config.Formatters.JsonFormatter;
            json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;
            json.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();

    // The api method [ActionName("CreateTest")] [Route("api/CreateTest")] [HttpPost] public HttpResponseMessage CreateTest() { UserAccount newAccount = new UserAccount(); newAccount.Name = "Testname"; newAccount.Password = "password"; newAccount.Email = "email";

            return Request.CreateResponse(HttpStatusCode.Accepted, "Successfully TestCreate");
    Sunday, August 26, 2018 11:33 AM

All replies

  • User364855 posted


    Which HttpPost attribute are you using? I think you should use System.Web.Http. https://stackoverflow.com/questions/15718741/405-method-not-allowed-web-api

    Monday, August 27, 2018 7:01 AM