1

I try to make a multiple-thread requester in order to test answer time of my server.

My server is a WCF webservice, and my client has a service reference to this webservice.

WCF respect HTTP specifications, and I see on many websites WCF is Keep-Alive enabled by default. By only two connections from the same client are authorized at same time.

So, when I try to create 100 threads, only two of them are processing at the same time. So, after few loops, a lot of threads are in timeout.

I try to follow this article : WCF wsHttpBinding with http keepalive but it didn't work.

Here is my app config (modified by the Service Reference) :

<?xml version="1.0"?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_ISabIn" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://xxx.xxx.xxx.xxx:xxx/SabIn.svc" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_ISabIn" contract="TestWs.ISabIn"
                name="BasicHttpBinding_ISabIn" />
        </client>
    </system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

I try to use customBinding in the appCode, like this article : HTTP Keep-alive and ServiceHost / C#? but, when I execute my software, an erreor appears about "application/xml". If I try to translate in english, it would be somehting like "your client don't manage the application/xml message".

I need to do real-time transactions, and I can't if WCF only manage two sockets at same time...

Can you help me ?

PS : I can post the code of my client, but I'm not sure is useful since I know the problem is a sockets limitation.

SOLUTION (thnaks to Spender) : at the beginning of your code, change the default value (it is 2) in System.Net.ServicePointManager.DefaultConnectionLimit

Community
  • 1
  • 1
BaptX
  • 561
  • 1
  • 7
  • 21

1 Answers1

2

Isn't this caused by default .net limits on HTTP request to a single host? This is because ServicePointManager.DefaultConnectionLimit defaults to 2.

When you issue an HTTP request, internally, a ServicePoint instance is created to manage the connections to a specific host. Make a new request to the same host, and it will use the same ServicePoint instance for connection management.

You can manipulate the limit for a single host with the following code:

var serviceUri = new Uri("http://xxx.xxx.xxx.xxx:xxx/SabIn.svc");
var servicePoint = System.Net.ServicePointManager.FindServicePoint(serviceUri);
servicePoint.ConnectionLimit = int.MaxValue;

I believe you can also handle this in web.config/app.config but I'm not sure if you can tweak limits associated with a single ServicePoint.

spender
  • 117,338
  • 33
  • 229
  • 351