Limiting the number of outgoing SOAP web service calls

If you create a web app, which consume information from other web services, you eventually need a possibility to control the number of outgoing SOAP web requests. On the one hand, the default maximum number of connections is 2, which could be a performance bottleneck. On the other hand, if you call another web service too intense, you may be banned there either technically (by a firewall or Windows server itself detecting DOS attack) or manually by a server administrator.
You can set the number of connections so:
ServicePointManager.DefaultConnectionLimit = 25
or so:

ServiceReference1.BackendServiceSoapClient cl = new BackendServiceSoapClient();
ServicePoint p = ServicePointManager.FindServicePoint(cl.Endpoint.Address.Uri);
p.ConnectionLimit = 20000;

You can tell how many connections are open so:


One interestring point it that although .NET uses background threads to handle connections, the number of threads doesn’t correspond to the number of opened connections. For example, when I set the limit to 20000, I actually see 20000 opened TCP connections in the performance monitor, but only 18 running threads. Does anybody have any info about how it works?

Leave a comment