在Azure上托管的webapi始终会收到一个空列表

时间:2018-11-01 06:09:23

标签: asp.net azure asp.net-web-api

这是场景。我将14个对象的列表发送到托管在azure上的webapi。但是它总是收到一个空列表。我像这样从后端调用webapi。

using (HttpClient objHttpCLient = new HttpClient())
                {
                    HttpResponseMessage objMessage = objHttpCLient.PostAsync(new Uri(strUrl), new StringContent(JOContent.ToString(), Encoding.UTF8, "application/JSON")).Result;
                    var ResponseClientConfiguration = objMessage.Content.ReadAsStringAsync();
                    sw.WriteLine(objMessage.StatusCode.ToString());
                    if (objMessage.IsSuccessStatusCode)
                    {
                        sw.WriteLine(ResponseClientConfiguration.Result);
                        objResponse = JObject.Parse(ResponseClientConfiguration.Result);
                        strConfigurationJSON += objResponse["ConfigurationJson"].ToString();
                    }
                }

现在,当将webapi安装在我的本地环境中时,此方法可以完美工作。它会接收所有144个对象,但是一旦将其托管在天青石上,就会始终收到一个空的灯光。

1 个答案:

答案 0 :(得分:0)

这是解决方案。我仍然不知道为什么将webApi项目托管在azure上但在本地托管或普通的Web服务器托管时上述工作不起作用。解决方法是创建一个覆盖对象列表的类,即对象列表现在将是该类的属性。

在我对webApi期望的参数之前,如下所示

public JObject Validate(List<DateTime> lstDates)

在此之后

public JObject Validate(DateLst objDates)

DateLst类结构如下

public class DateLst 
{

  public List<DateTime> lstDates{ get; set;}

}

现在为什么能行之有效,而前者却无法发挥作用仍然是一个谜。