0

I am creating a web service in visual studio 2015 using MySQL databases. I want implement only a GET method using HTTP. Now when I am doing it I cam accross and error. Which is

cannot implicitly convert type 'system.net.http.httpresponsemessage' to 'system.web.httpresponse'

The point where it comes is below

public HttpResponse Get()
    {
        try
        {
            return  Request.CreateResponse(HttpStatusCode.Found, mEntities.meters_info_dev.ToList());
        }
        catch (Exception)
        {
            return Request.CreateErrorResponse(HttpStatusCode.NotFound, "No Data found");
        }
    }

Below is the image

enter image description here

I couldn't find the solution for it. Any help would be highly appreciated

3
  • 2
    Try changing the return type from HttpResponse to HttpResponseMessage as thats what you are making Commented Sep 26, 2017 at 9:29
  • I have changed it now it's giving me {"Message":"No Data found"} Commented Sep 26, 2017 at 9:32
  • There is insufficient info to pass comment on this - plus thats a whole new question and needs you to do a viable minimal reproducible etc.. Commented Sep 26, 2017 at 9:35

1 Answer 1

0

Directly it will not take the implicit conversion as expected But we can use HttpResponseMessage/HttpWebResponse type function to avoid the above issue. I have mentioned some sample code, it may help you.

[HttpPost]
        [Route("AddorUpdatePersonalInfo")]
        public async Task<HttpResponseMessage> AddorUpdatePersonalInfo([FromBody]PersonalInfo personalinfo)
        {
            try
            {
                var result = await this._Personalinforepository.AddorUpdatePersonalInfo(personalinfo);
                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, result);
                return response;
            }
            catch(Exception ex)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.