I have the following code:
using (var fact = new WebChannelFactory<IService<Message>>(binding,
commsSettings.MessageEndPoint()))
{
using (IDisposable channel = (IDisposable)fact.CreateChannel())
{
service = (IService<Message>)channel;
service.Create(AlertMessage);
((IClientChannel)channel).Close();
}
fact.Close();
}
Even though I am disposing the WebChannelFactory and the Channel itself, they are leaving connections open. I know this because in a performance test, the calls start timing out at the 10th call, and if I do netstat -a at the command line I can see a whole bunch of sockets open between my local machine and itself on port 80.
How can I make the proxy close its socket?
The problem was server-side. We had a leak of a signal-R client per service instance, which used up the available sockets.
When that happened, clients could no longer connect.
Hint for anyone else debugging something similar: Look at your server and see if it is not constructing some kind of WCF client and not cleaning them up. The symptom that gave it away was that the sockets seen with netstat -a still remained in an ESTABLISHED state after the client process had been terminated.