在.net core2.0下,项目在linux系统中调用webservice/wfc,随着时间变长,发现内存占用越来越大。
我们知道通过安装 WCF Web Service Reference Provider, 根据提示填写接口地址后, 会自动给我们生成一个 xxSoapClient 的类, 通过这个类我们可以调用webservice/wfc。
我的做法是
var clinet = new xxSoapClient();
var channel = client.ChannelFactory.CreateChannel();
//channel.调用具体业务接口()
随着时间推移,出现内存溢出。一开始以为是没有关闭,改造为:
var clinet = new xxSoapClient();
var channel = client.ChannelFactory.CreateChannel();
//channel.调用具体业务接口()
channel.Close()
测试后,仍旧会内存溢出。
github上也有人反馈过此类问题:
https://github.com/dotnet/wcf/issues/2351
目前来看应该算是官方的bug。
当前的解决方案只能改为单例调用,到目前没发现问题。
改为单例的时候注意下client.State的值, 如果发现已关闭,请重新创建实例。