c# - 基于 ServiceStack 的 REST 服务为日志运行进程提供超时
问题描述
我需要通过 ServiceStack 服务运行 1 次长时间运行的操作(大约 10 分钟)。我在本地计算机上运行这一切,ServiceStack 在 IIS 和 .NET 5 上运行。现在它给出了超时,我不知道是什么原因(顺便检查了我的 IIS 设置)。我的部分代码(我删除了一些不相关的代码):
static async Task Main(string[] args)
{
var jsonServiceClient = new JsonServiceClient("http://localhost/services");
jsonServiceClient.Timeout = TimeSpan.FromMinutes(20);
await CorrectCreationDates(jsonServiceClient);
}
private static async Task CorrectCreationDates(JsonServiceClient jsonServiceClient)
{
var request = new CorrectCreationDatesRequest();
var result = await jsonServiceClient.PostAsync(request);
}
这是一个例外:
System.Net.WebException:“操作已超时。”
此异常最初是在此调用堆栈中引发的:ServiceStack.AsyncServiceClient.SendWebRequestAsync(string, string, object, System.Threading.CancellationToken, bool) in AsyncServiceClient.cs System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices .TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task) System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) System.Runtime.CompilerServices.TaskAwaiter.GetResult() Gloneco.Importer.Program.CorrectCreationDates( ServiceStack.JsonServiceClient) 在 Program.cs System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task) System.Runtime.CompilerServices.TaskAwaiter。HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) System.Runtime.CompilerServices.TaskAwaiter.GetResult() ... [调用堆栈被截断]
解决方案
ServiceStack 本身不会施加任何请求限制,任何限制都由底层 HTTP 服务器施加,例如,如果您使用 IIS,请查看如何在 IIS答案中增加请求超时。
推荐阅读
- python - Django REST 框架 - MultiSelectField - TypeError:“set”类型的对象不是 JSON 可序列化的
- azure-application-gateway - 我应该将证书放在 App Gw 和 Web App 级别
- java - 如何在没有任何功能文件的情况下运行黄瓜?
- java - 在我的 java 表中看不到列数据,问题
- sql - 如何根据特定文本在 SQL 中创建循环?
- php - 通过他们在 php 中的 API 清除 Cloudflare 缓存
- sql - 我需要选择在一列中有多个记录的客户
- rest - REST 完整 API 复合键与主键
- node.js - Heroku 上将 Angular 调用代理到后端 API 的正确方法是什么?
- java - 访问 H2 DB 时未找到表“myTable”错误