azure - 内部服务器错误 - Azure 应用服务自定义 Controller

标签 azure azure-web-app-service

我有一个 Azure 移动应用服务(不是旧的移动服务),带有多个自定义 Controller ,并且流程运行良好。

今天发生了关于内部服务器错误的错误。

我附加了调试器并逐步执行代码, Controller 到达末尾,没有任何错误,并返回Ok。因此我一直没能找到根源。但客户端随后收到错误消息,指出存在内部服务器错误。

我进行服务器调用,如下所示:

DTO.UserDTO uploadImage = await ((App)Application.Current).MobileService.InvokeApiAsync<DTO.UsernameCheckDto, DTO.UserDTO>("user/blobStorageRetrieval", new DTO.UsernameCheckDto() { Username = ((App)Application.Current).InGameUserName }, System.Net.Http.HttpMethod.Post, null);

自定义 Controller 结尾为:

return Ok(new UserDTO()
{
    MicrosoftId = stable_sid,
    Username = stable_users.Username,
    playerNames = playerNames,
    playerScores = playerInts,
    isCreated = true,
    bestScore = stable_users.bestRunnerScore,
    statsInformation = _statsInformation,
});

我已经验证所有变量都已初始化。 UserDTO 类型是从同一个可移植库引用的。有人能提示我如何找到此错误的原因吗? Controller 之前一直工作,没有任何改变。

一般错误消息

"The request could not be completed. (Internal Server Error)" string

回应

{StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: { Server: Microsoft-IIS/8.0 Date: Fri, 30 Sep 2016 17:37:57 GMT X-Powered-By: ASP.NET Content-Length: 36 Content-Type: application/json; charset=utf-8 }} System.Net.Http.HttpResponseMessage

堆栈

StackTrace " at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient.d__24.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient.d__26.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient.d__18.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.WindowsAzure.MobileServices.MobileServiceClient.d__69.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.WindowsAzure.MobileServices.MobileServiceClient.d__63 2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at Stonegaard_endless_runner.MainPage.d__7.MoveNext()" string

解决方案建议

正在 stackoverflow 上搜索 Sid。并发现了2年前的问题。 Web API converted to Azure Mobile Service not serializing all properties

我明天会尝试这个。

最佳答案

解决方案是添加:

httpConfig.Formatters.JsonFormatter.SerializerSettings.DefaultValueHandling = Newtonsoft.Json.DefaultValueHandling.Include;
httpConfig.Formatters.JsonFormatter.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Include;

ConfigureMobileApp 方法中的 Startup.MobileApp.cs

关于azure - 内部服务器错误 - Azure 应用服务自定义 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39797262/

相关文章:

azure - 将 WebJob 添加到 Azure 应用服务 - 权限问题

azure - 如何使用管理 API 发布 Azure Web 应用程序?

c# - 成功部署后Az​​ure Web应用程序未更新

javascript - Azure MobileService EasyApi java.lang.interruptedException

c# - Azure C# 应用服务 ODBC 连接到 Redshift

node.js - 在 Windows/Azure 中重命名长路径时 npm 3.x 安装失败

python - Azure 免费网站与 Python Django 未运行

azure - 是否可以在单个应用程序服务下拥有多个 Web 应用程序?

.net - 调用 RunAndBlock 后是否可以将动态生成的函数绑定(bind)到 Azure WebJobs JobHost?

c# - 在 Azure Function 中访问 VSTS 构建服务器版本