MattW
MattW

Reputation: 13212

Set max number of Outbound Requests Programatically (System.Net) rather than App.Config

I know I can add the following to a client to handle a higher volume of outbound requests:

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

Is there a way to do this in code, not in the app.config?

Upvotes: 1

Views: 639

Answers (1)

KMoraz
KMoraz

Reputation: 14164

This should do:

        Configuration config = WebConfigurationManager.OpenWebConfiguration("/YourSiteRoot");
        ConnectionManagementSection connectionManagementSection =
            (ConnectionManagementSection)config.GetSection("system.net/connectionManagement");

        connectionManagementSection.ConnectionManagement.Add(new ConnectionManagementElement("*", 65535));

        if (config.HasFile)
            config.Save();

Upvotes: 1

Related Questions