Код: Выделить всё
ConsoleAppКогда API проект запускается с Kestrel , через несколько секунд я получаю эту ошибку:
Код: Выделить всё
System.Net.Http.HttpRequestException: An error occurred while sending the request.
---> System.IO.IOException: Unable to write data to the transport connection: An established connection was aborted by the software in your host machine..
---> System.Net.Sockets.SocketException (10053): An established connection was aborted by the software in your host machine
Код: Выделить всё
var services = new ServiceCollection();
services.AddHttpClient("Test", options =>
{
options.BaseAddress = new Uri("http://127.0.0.1:34399");
options.Timeout = TimeSpan.FromMinutes(5);
})
.RemoveAllLoggers();
var builder = services.BuildServiceProvider();
var httpClientFactory = builder.GetRequiredService();
List tasks = new List();
for (int i = 0; i < 100_000; i++)
{
tasks.Add(CallApi(httpClientFactory));
}
await Task.WhenAll(tasks);
static async Task CallApi(IHttpClientFactory httpClientFactory)
{
try
{
var client = httpClientFactory.CreateClient("Test");
await client.GetAsync("/WeatherForecast");
}
catch (Exception ex)
{
Console.WriteLine(ex);
throw;
}
}
< /code>
И это проект API: < /p>
[HttpGet(Name = "GetWeatherForecast")]
public async Task Get()
{
await Task.Delay(10);
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... rel-doesnt
Мобильная версия