ASP.Net Core 2.1上的Azure移动后端连接问题

时间:2018-07-23 16:34:53

标签: c# asp.net azure-mobile-services asp.net-core-2.1

我正在使用ASP.Net Core Web应用程序,并且尝试通过Azure移动后端将其连接。

后端可以与其他Windows桌面应用程序很好地协同工作。 到目前为止,后端与ASP.Net Core v2.0的运行情况都很好。 昨天我安装了ASP.Net Core 2.1 SDK,并将Microsoft.AspNetCore.All nuget程序包从2.0更新到了2.1.2,从那时起,我收到以下异常: MobileServiceInvalidOperationException-“服务器未提供预期内容的响应。”

您能告诉我解决此问题的任何解决方案吗?

2 个答案:

答案 0 :(得分:4)

  

此外,到目前为止,后端与ASP.Net Core v2.0都运行良好。昨天,我安装了ASP.Net Core 2.1 SDK,并将Microsoft.AspNetCore.All nuget软件包从2.0更新到2.1.2,此后,我收到以下异常:MobileServiceInvalidOperationException-“服务器未提供预期的响应内容。”

根据您的描述,您的Azure移动后端可以按预期与ASP.Net Core v2.0一起使用。 AFAIK,移动后端只是为您提供公开Table / API端点的简单方法。此外,您的Web应用如何通过HttpClient或Azure Mobile Client SDK与移动后端连接的?

对于解决此问题的简单方法,可以为Azure移动应用启用诊断日志记录以检索详细的错误消息以缩小此问题的范围,有关详细信息,请关注here

答案 1 :(得分:1)

我有相同的问题,但没有解决方案。我在MobileServiceHttpClient函数的SendRequestAsync(...)代码中找到了下面的代码行。

// If there was supposed to be response content and there was not, throw        
if (ensureResponseContent)
{
   long? contentLength = null;

   if (response.Content != null)
   {
      contentLength = response.Content.Headers.ContentLength;
   }

   if (contentLength == null || contentLength <= 0)
   {
        throw new MobileServiceInvalidOperationException("The server did not provide a response with the expected content.", request, response);
   }
}

看着response.Content.Headers.ContentLength,它是null。将应用程序作为2.0核心项目运行时,该值已正确填写。奇怪的是内容在那里。

如果您深入查看私有成员,则其中一些设置正确。

catch (MobileServiceInvalidOperationException msioe)
{
    //content will contain the correct json but the ContentLenth is null!?!
    string content = await msioe.Response.Content.ReadAsStringAsync();

}

这是一个2.1核心问题。希望他们能解决它。