Pro*_*Sky 5 c# asp.net-web-api .net-core asp.net-core-webapi
我有一个.net核心网络api,端点之一运行存储过程,该过程需要3-4分钟才能完成。API已部署到IIS。
当我执行httpGet时,出现502 Bad Gateway错误。查看IIS日志,该错误实际上是超时。这来自IIS日志:
2018-11-28 17:24:48 10.71.12.59 GET /api/meetingreport fromDate=11/01/2018&toDate=11/30/2018&tradingGroup=All&symbol=&reviewed= 16000 - 10.6.50.61 Mozilla/5.0+(Windows+NT+6.1;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/64.0.3282.140+Safari/537.36 - 502 3 12002 120029
错误代码12202适用于ERR_WINHTTP_TIMEOUT。2分钟后发生超时。请求时间少于2分钟即可正常运行。我通过添加超过2分钟和不足2分钟的thread.sleep进行了检查。
[HttpGet("")]
public async Task<IActionResult> Get([FromQuery(Name = "fromDate")] DateTime fromDate,
[FromQuery(Name = "toDate")] DateTime toDate, [FromQuery(Name ="tradingGroup")]string tradingGroup, [FromQuery(Name = "symbol")]string symbol, [FromQuery(Name = "reviewed")]string reviewed)
{
try
{
if (fromDate == DateTime.MinValue || toDate == DateTime.MinValue) return BadRequest("fromDate and toDate is a required Field");
tradingGroup = tradingGroup == "All" ? tradingGroup.Replace("All", "") : tradingGroup;
tradingGroup = tradingGroup ?? string.Empty;
symbol = symbol ?? string.Empty;
var result = await _meetingReportRepository.GetMeetingReport(fromDate, toDate, tradingGroup, symbol, reviewed);
Thread.Sleep(132000); // 2.2 minutes
return Ok(result);
}
catch (Exception ex)
{
}
return BadRequest($"Couldn't Genererate Report");
}
Run Code Online (Sandbox Code Playgroud)
这是POSTMAN的错误。
如何将超时时间增加到10分钟?有指针吗?没有Web.config文件。
在这篇文章之后,我更新了program.cs以添加10分钟的KeepAliveTimeout。但这没有帮助。2分钟后,我的请求仍然超时。
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseKestrel( o=> { o.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(10); })
.Build();
Run Code Online (Sandbox Code Playgroud)
编辑1: 当部署到IIS时,将创建一个web.config文件,其内容如下:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\project.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</location>
</configuration>
Run Code Online (Sandbox Code Playgroud)
我将在此处添加超时以查看是否有效。
编辑2: 添加requestTimeout达到目的。IIS非常忠实于web.config :)。我的问题已解决。
<aspNetCore requestTimeout="00:20:00" processPath="dotnet" arguments=".\project.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
Run Code Online (Sandbox Code Playgroud)
将requestTimeout添加到web.confg解决了我的超时问题。
<aspNetCore requestTimeout="00:20:00" processPath="dotnet" arguments=".\project.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
Run Code Online (Sandbox Code Playgroud)
更好的方法是启动请求,然后按照@ steve-land的建议轮询结果
| 归档时间: |
|
| 查看次数: |
5150 次 |
| 最近记录: |