小编Bre*_*ane的帖子

为 ASP.NET Core 中的每个请求创建新的 WCF 客户端是否会导致套接字耗尽?

本文介绍了 HttpClient 的一个众所周知的问题,该问题可能导致套接字耗尽

我有一个 ASP.NET Core 3.1 Web 应用程序。在 .NET Standard 2.0 类库中,我按照此说明在 Visual Studio 2019 中添加了 WCF Web 服务引用。

在服务中,我按照文档中描述的方式使用 WCF 客户端。创建 WCF 客户端的实例,然后针对每个请求关闭客户端。

public class TestService
{
    public async Task<int> Add(int a, int b)
    {
        CalculatorSoapClient client = new CalculatorSoapClient();
        var resultat = await client.AddAsync(a, b);
        //this is a bad way to close the client I should also check
        //if I need to call Abort()
        await client.CloseAsync();
        return resultat;
    }
}
Run Code Online (Sandbox Code Playgroud)

我知道在没有任何检查的情况下关闭客户端是不好的做法,但就本示例而言,这并不重要。

当我启动应用程序并向使用 …

.net asp.net wcf web-services

5
推荐指数
1
解决办法
3292
查看次数

标签 统计

.net ×1

asp.net ×1

wcf ×1

web-services ×1