Web API method not returning the response

2019-06-10 16:14发布

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

0条回答
登录 后发表回答