public HttpResponseMessage Put(int id, [FromBody]DataModel model)
in the put method i pass the object and it get updated in the database. Its working i have checked it with fiddler.
Now in My MVC Application i call it using the following code
[HttpPost] public JsonResult OrderSearch(DataModel model)
{
UpdateOrder(model).Wait();
if (putresult != null && putresult != string.Empty)
{
return Json(putresult);
}
else
{
return Json("Error in getting result");
}
}
private async Task UpdateOrder(DataModel model) {
string json = JsonConvert.SerializeObject(model);
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(url);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new
MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = client.PutAsync("api/values/"+ model.OrderNo,new StringContent(json)).Result;
if (response.IsSuccessStatusCode)
{
putresult = await response.Content.ReadAsAsync
}
}
}
But the code does not hit my Put method on the service and putresult remains blank. I try to search about PutAsync usage but could not find anything. So i replace this code with
and comment out the action method it seem to hit as fiddler suggest but giving this
{"Message":"The requested resource does not support http method 'OPTIONS'."}
In my web api i also set these settings
i had done these settings as well in my web config
but even after that it does not seem to hit the correct method.

Mohit SharmaPosted Apr 16, 2014, 3:55 AM
Anupam SinghPosted Apr 16, 2014, 2:08 AM