Web API returning HttpResponseMessage object after nuget updates in Azure Web App

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-08 06:09:07

问题


I'm using Web API 5, it's has been working fine, I return a HttpResponseMessage object with Content = new StringContent("content here") and get the expected content when calling the API.

[HttpPost]
    public async Task<HttpResponseMessage> GetData([FromBody]DataObject input)
    {
      .....
      return new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(JsonConvert.SerializeObject(returnModel))
            };
    }

However, I recently updated a number of MVC and .NET NuGet packages, and now, while the project compiles and runs fine locally, when I deploy to an Azure Web App, calling the API returns the actual HttpResponseMessage object with no content, rather than the content:

{
"Version": {
    "_Major": 1,
    "_Minor": 1,
    "_Build": -1,
    "_Revision": -1
},
"Content": {
    "Headers": [
        {
            "Key": "Content-Type",
            "Value": [
                "text/plain; charset=utf-8"
            ]
        }
    ]
},
"StatusCode": 200,
"ReasonPhrase": "OK",
"Headers": [],
"RequestMessage": null,
    "IsSuccessStatusCode": true
}

Normally this same call would return a JSON string of the Content object. Is there some odd dependency issue happening, any ideas on how to fix without rolling back all of the nuget updates? Or do I need to update a setting on the Azure Web App (already have .NET 4.7 set).


回答1:


Well assuming an ApiController, the action can be refactored to use the more recent advised syntax.

[HttpPost]
public async Task<IHttpActionResult> GetData([FromBody]DataObject input) {

    //.....code awaited here and gets 'returnModel'

    return Ok(returnModel);
}


来源:https://stackoverflow.com/questions/51969826/web-api-returning-httpresponsemessage-object-after-nuget-updates-in-azure-web-ap

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