none
How do I set ServicePointManager.DefaultConnectionLimit in the portable framework? RRS feed

  • Question

  • I need to use multiple tasks that will hit a webservice end point. Each task will be streaming data and will have a httpWebRequest connection open.

    I need to set the property ServicePointManager.DefaultConnectionLimit to a value greater than 2, but I'm using the portable framework and the ServicePointManager class is not available (should be in System.Net).

    How do I allow more open webrequests in the portable framework?

    Regards.

    • Moved by Fred Bao Monday, August 18, 2014 2:50 AM WCF Related
    Saturday, August 16, 2014 3:39 PM

Answers

  • How do I allow more open webrequests in the portable framework?

    Hi,

    By default the httpWebRequest in C# is using connection pool to improving performance & respect restrictions, so one user agent SHOULD NOT create more than 2 connection to a server.
    One of the workaround is to add a few lines in App.config source in MSDN:

    <configuration> 
    
      <system.net> 
    
        <connectionManagement> 
    
          <add address="*" maxconnection="1000" /> 
    
        </connectionManagement> 
    
      </system.net> 
    
    </configuration> 

    For more information, please try to refer to the following article:
    #HttpWebRequest can only establish 2 connections to the same server endpoint or not:
    https://sites.google.com/site/softwaretechforge/Downhome/Programminglanguage/chttpwebrequestcanonlyestablish2connectionstothesameserverendpoint .

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, August 26, 2014 2:24 AM
    Moderator

All replies

  • Hello Cafe,

    I move this thread to the WCF forum for getting better help.

    Best Regards,

    Fred.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, August 18, 2014 2:50 AM
  • I'm not familiar with the technique, maybe you could find your answer in the article below:

    http://msdn.microsoft.com/en-US/en-us/library/system.net.servicepointmanager.defaultconnectionlimit(v=vs.110).aspx

    Tuesday, August 19, 2014 2:52 AM
  • I could not find a way to have more than 2 connections using webrequest objects in the portable framework, but I did find a way to have more concurrent connections. I'm just using the HttpClient class.

    In my tests, when using HttpClient, you can use more than 2 concurrent connections. I have tried 10 and works fine.

    The following test has 10 concurrent connections:

       var clients = new List<System.Net.Http.HttpClient>();
    
            for (int i = 0; i < 10; i++)
            {
                var client = new System.Net.Http.HttpClient();
    
                var response = client.GetAsync("http://www.google.com").Result;
    
                clients.Add(client);
            }
            foreach (var client in clients)
                client.Dispose();

    This is a workaround. My original question, however, remains unanswered.



    Tuesday, August 19, 2014 2:59 PM
  • How do I allow more open webrequests in the portable framework?

    Hi,

    By default the httpWebRequest in C# is using connection pool to improving performance & respect restrictions, so one user agent SHOULD NOT create more than 2 connection to a server.
    One of the workaround is to add a few lines in App.config source in MSDN:

    <configuration> 
    
      <system.net> 
    
        <connectionManagement> 
    
          <add address="*" maxconnection="1000" /> 
    
        </connectionManagement> 
    
      </system.net> 
    
    </configuration> 

    For more information, please try to refer to the following article:
    #HttpWebRequest can only establish 2 connections to the same server endpoint or not:
    https://sites.google.com/site/softwaretechforge/Downhome/Programminglanguage/chttpwebrequestcanonlyestablish2connectionstothesameserverendpoint .

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, August 26, 2014 2:24 AM
    Moderator