Last week I encountered a problem while connecting to a WCF service (more accurate a WWF in a WCF). The error message was : “Client is unable to finish the security negotiation within the configured timeout (00:01:00). The current negotiation leg is 1 (00:01:00).” A timeout at the security negotiation, why? I have a lot of programs with connections to WCF and I never had this error message before. The reason is the number of connections opened and closed in a certain period of time.
Explanation : my program create 20 threads, each thread create a connection to the WCF service, open, do the call and close the connection properly. Why this error message? It’s a windows reason, a socket connection in windows remain not accessible when closed for a period of time, the default is 4 minutes and can be changed by a registry value. The connection is in a pool, and we must ask a connection from the same pool to be able to retrieve the same connection and that’s the problem, each time I create a new connection from a different pool and I reach the maximum allowed sockect connection.
How to resolve the problem?
It’s not so difficult, Difficult in WWF.
The pool of connection is created by the ChannelFactory class, so if you create a connection always from the same ChannelFactory, you will use the pool. So don’t use the statis method CreateChannel because you’ll always create a new pool.
WCF reference added via “Add service reference” in visual studio (svcutil.exe)
If you add the reference, the generated proxy’ll use the pool.
If you create your own proxy
Create a ChannelFactory object, and create the channel always from this object, it’ll use the same socket pool. Don’t call the static method from the ChannelFactory class.
From a WWF (worflow)
It’s more difficult because you don’t create the code to call a WCF (you can), you normally use a send activity, by default it doesn’t use the pool. If you want to use the pool, you need to use ChannelManagerService to say on which end point you want to use pooling. If you want to read more about, read the following post about Serge Lucas, it is the detailed solution for this problem.