首页 > 解决方案 > 基于 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() ... [调用堆栈被截断]

标签: c#restservicestack

解决方案


ServiceStack 本身不会施加任何请求限制,任何限制都由底层 HTTP 服务器施加,例如,如果您使用 IIS,请查看如何在 IIS答案中增加请求超时。


推荐阅读