System Description: I have a WCF service (self hosted in a windows service) which is consumed by a client (also a windows service). The two applications are designed to have constant uptime. The 'queue' application reads entries from a database, sends 'jobs' to the WCF service for processing which returns some information to the client, and the client stores the results back into the DB.
Error Details: After around two hours the client application can no longer connect to the WCF service reporting the error:
"Insufficient winsock resources available to complete socket connection initiation.",
A second application which runs on the same server also starts throwing exceptions from this time onwards:
"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"
The second application is nothing to do with the WCF client and server, it just runs on the same server and simply reads/writes to a database.
Server/Client setup/code:
Server Details:
- Self hosted inside a windows service.
- netTcpBinding
- receiveTimeout="00:00:15"
- serviceThrottling maxConcurrentCalls="2147483647"
- maxConcurrentSessions="2147483647"
Client Connection Class::
public class ClientConnectionClass : ClientBase<IFileService>, IFileService, IDisposable
{
public void callMethod(InputRequest request)
{
result = base.Channel.doRequest(request);
}
void Dispose()
{
bool success = false;
try
{
if (State != CommunicationState.Faulted)
{
Close();
success = true;
}
}
finally
{
if (!success)
{
Abort();
}
}
}
}
Client Process (windows service):
while(true)
{
// Do some stuff before, code ommited
ClientConnectionClass ccc = new ClientConnectionClass();
ccc.callMethod(inputRequest);
// Do some stuff with the response
// Close the connection class, is this the right way to close it?
ccc.Close();
Thread.Sleep(1000);
}
Possible Explanations: I think that based on the first exception error, the code is not closing/releasing socket connections or running out of ports to connect on (please note I am explicitly calling the Close() method of the ClientBase from the ClientProcess, in addition to implementing the Dispose() method on the ClientBase).
Notes: Client application is multi-threaded, has up to 4 concurrent threads running at the same time, each of which calls the WCF service. The client to WCF service is fully working up until the 2 hour (ish) point where the Client Process then spits out errors, and other (unrelated) Windows Services (which use network resources) also start to spit out errors.
Possible Questions to answer: Am I creating/disposing of the Class that implements the ClientBase class? Is there any easier way to debug/log the current state of either the Client or WCF service ( I have attached perfmon.exe, but it doesn't really give much useful information on the socket/network side of things ).
Thanks
UPDATE: I have actually now wrapped the ClientConnectionClass into a 'using' statement, I am currently testing this ( which usually takes 2 hours ). Update, this did not work.