Web API method not returning the response

允我心安 提交于 2019-12-08 09:50:31

问题


I have a requirement to use Web API. I have implemented Add functionality successfully , and now in the Edit . I am calling the PUT method from my mvc controller thorough and intermediate class and which returns return Request.CreateResponse(HttpStatusCode.OK); This is the return from my PUT method

public HttpResponseMessage SampleEdit(int sampleId, Sample sample)
        {
            string uri = baseUri + "Sample/" + sampleId;
            using (HttpClient httpClient = new HttpClient())
            {

                Task<HttpResponseMessage> response = httpClient.PutAsJsonAsync<Sample>(uri, sample);


                return **JsonConvert.DeserializeObjectAsync<HttpResponseMessage>(response.Result.Content.ReadAsStringAsync().Result).Result;**
            }
        }

Here if i debug the put method is called and it is setting the status .

HttpResponseMessage message =
DatabaseService.SampleEdit(sample.SampleID,sample);

This message is coming as null if the return statement in PUT is Request.CreateResponse(HttpStatusCode.OK); If i use

Request.CreateResponse(HttpStatusCode.OK,sample); 

instead it is returning the status. What would be the issue

来源:https://stackoverflow.com/questions/35338684/web-api-method-not-returning-the-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!