I have written an Asp.Net web api in which i wrote put, post,get and delete to perform crud in Sql azure database. Database and API are both live on Microsoft Azure. I am successfully able to call GET controller and fetch data in browser. When i try to post hard coded data to it via a console app, it does nothing (neither gives error nor exception). Below is the Web API controller:
public HttpResponseMessage Post([FromBody] Product prod)
{
try
{
se.Products.Add(prod);
se.SaveChanges();
var message = Request.CreateResponse(HttpStatusCode.Created, prod);
message.Headers.Location = new Uri(Request.RequestUri + prod.Product_ID.ToString());
return message;
}
catch (Exception ex)
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
}
}
Method from the client console app to send data is shown in this picture
I tried to inspect this method by putting a breakpoint at response.Response got nothing in it but showed a bad request. Here is the screenshot to it.
Kindly help me how to successfully post data to database via web api hosted on azure. Thanks :)