簡體   English   中英

無法將類型“system.net.http.httpresponsemessage”隱式轉換為“system.web.httpresponse”

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

我正在使用MySQL數據庫在visual studio 2015創建web service 我只想使用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");
        }
    }

下面是圖片

在此處輸入圖片說明

我找不到解決方案。 任何幫助將不勝感激

直接它不會像預期的那樣進行隱式轉換但是我們可以使用 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));
            }
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM