我使用web service
数据库在visual studio 2015
中创建MySQL
。我想只使用HTTP
实现GET方法。现在,当我这样做的时候,我突然发现错误。这是
cannot implicitly convert type 'system.net.http.httpresponsemessage' to 'system.web.httpresponse'
它到底的地方是
public HttpResponse Get()
{
try
{
return Request.CreateResponse(HttpStatusCode.Found, mEntities.meters_info_dev.ToList());
}
catch (Exception)
{
return Request.CreateErrorResponse(HttpStatusCode.NotFound, "No Data found");
}
}
下面是图片
我找不到它的解决方案。任何帮助都将受到高度赞赏
答案 0 :(得分:0)
直接它不会像预期的那样进行隐式转换,但是我们可以使用HttpResponseMessage / HttpWebResponse类型的函数来避免上述问题。我已经提到了一些示例代码,可能会对您有所帮助。
[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));
}
}