ServicePoint Class


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Provides connection management for HTTP connections.

Namespace:   System.Net
Assembly:  System (in System.dll)


public class ServicePoint


Gets the Uniform Resource Identifier (URI) of the server that this ServicePoint object connects to.


Specifies the delegate to associate a local IPEndPoint with a ServicePoint.


Gets the certificate received for this ServicePoint object.


Gets the last client certificate sent to the server.


Gets or sets the number of milliseconds after which an active ServicePoint connection is closed.


Gets or sets the maximum number of connections allowed on this ServicePoint object.


Gets the connection name.


Gets the number of open connections associated with this ServicePoint object.


Gets or sets a Boolean value that determines whether 100-Continue behavior is used.


Gets the date and time that the ServicePoint object was last connected to a host.


Gets or sets the amount of time a connection associated with the ServicePoint object can remain idle before the connection is closed.


Gets the version of the HTTP protocol that the ServicePoint object uses.


Gets or sets the size of the receiving buffer for the socket used by this ServicePoint.


Indicates whether the ServicePoint object supports pipelined connections.


Gets or sets a Boolean value that determines whether the Nagle algorithm is used on connections managed by this ServicePoint object.


Removes the specified connection group from this ServicePoint object.


Determines whether the specified object is equal to the current object.(Inherited from Object.)


Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)


Serves as the default hash function. (Inherited from Object.)


Gets the Type of the current instance.(Inherited from Object.)


Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethodSetTcpKeepAlive(Boolean, Int32, Int32)

Enables or disables the keep-alive option on a TCP connection.


Returns a string that represents the current object.(Inherited from Object.)

The ServicePoint class handles connections to an Internet resource based on the host information passed in the resource's Uniform Resource Identifier (URI). The initial connection to the resource determines the information that the ServicePoint object maintains, which is then shared by all subsequent requests to that resource.

ServicePoint objects are managed by the ServicePointManager class and are created, if necessary, by the ServicePointManager.FindServicePoint method. ServicePoint objects are never created directly but are always created and managed by the ServicePointManager class. The maximum number of ServicePoint objects that can be created is set by the ServicePointManager.MaxServicePoints property.

Each ServicePoint object maintains its connection to an Internet resource until it has been idle longer than the time specified in the MaxIdleTime property. When a ServicePoint exceeds the MaxIdleTime value, it can be recycled to another connection. The default value of MaxIdleTime is set by the ServicePointManager.MaxServicePointIdleTime property.

When the ConnectionLeaseTimeout property is set to a value other than -1, and after the specified time elapses, an active ServicePoint connection is closed after it services the next request. This is useful for applications that do not require active connections that are opened indefinitely, as they are by default.


In high load conditions, some applications may run out of free threads in the ThreadPool, which may lead to poor system performance (such as high and variable transaction times). See for a number of configuration changes you can make to fix this issue.

The following code example creates a ServicePoint object that connects to the URI

// This example shows how to use the ServicePoint and ServicePointManager classes.
// The ServicePointManager class uses the ServicePoint class to manage connections
// to a remote host. The networking classes reuse service points for all 
// requests to a given URI. In fact, the same ServicePoint object 
// is used to issue requests to Internet resources identified by the same
// scheme identifier (for example,  HTTP) and host fragment (for example,  
// This should improve your application performance. 
// Reusing service points in this way can help improve application performance.
using System;
using System.Net;
using System.Threading;
using System.Text.RegularExpressions;

namespace Mssc.Services.ConnectionManagement
    class TestServicePoint
        private static void ShowProperties (ServicePoint sp)
            Console.WriteLine ("Done calling FindServicePoint()...");

            // Display the ServicePoint Internet resource address.
            Console.WriteLine ("Address = {0} ", sp.Address.ToString ());

            // Display the date and time that the ServicePoint was last 
            // connected to a host.
            Console.WriteLine ("IdleSince = " + sp.IdleSince.ToString ());

            // Display the maximum length of time that the ServicePoint instance  
            // is allowed to maintain an idle connection to an Internet  
            // resource before it is recycled for use in another connection.
            Console.WriteLine ("MaxIdleTime = " + sp.MaxIdleTime);

            Console.WriteLine ("ConnectionName = " + sp.ConnectionName);

            // Display the maximum number of connections allowed on this 
            // ServicePoint instance.
            Console.WriteLine ("ConnectionLimit = " + sp.ConnectionLimit);

            // Display the number of connections associated with this 
            // ServicePoint instance.
            Console.WriteLine ("CurrentConnections = " + sp.CurrentConnections);

            if (sp.Certificate == null)
                Console.WriteLine ("Certificate = (null)");
                Console.WriteLine ("Certificate = " + sp.Certificate.ToString ());

            if (sp.ClientCertificate == null)
                Console.WriteLine ("ClientCertificate = (null)");
                Console. WriteLine ("ClientCertificate = " + sp.ClientCertificate.ToString ());

            Console.WriteLine ("ProtocolVersion = " + sp.ProtocolVersion.ToString ());
            Console.WriteLine ("SupportsPipelining = " + sp.SupportsPipelining);

            Console.WriteLine ("UseNagleAlgorithm = " + sp.UseNagleAlgorithm.ToString ());
            Console.WriteLine ("Expect 100-continue = " + sp.Expect100Continue.ToString ());

        private static void makeWebRequest (int hashCode, string Uri)
            HttpWebResponse res = null;

            // Make sure that the idle time has elapsed, so that a new 
            // ServicePoint instance is created.
            Console.WriteLine ("Sleeping for 2 sec.");
            Thread.Sleep (2000);
                // Create a request to the passed URI.
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create (Uri);

                Console.WriteLine ("\nConnecting to " + Uri + " ............");

                // Get the response object.
                res = (HttpWebResponse)req.GetResponse ();
                Console.WriteLine ("Connected.\n");

                ServicePoint currentServicePoint = req.ServicePoint;

                // Display new service point properties.
                int currentHashCode = currentServicePoint.GetHashCode ();

                Console.WriteLine ("New service point hashcode: " + currentHashCode);
                Console.WriteLine ("New service point max idle time: " + currentServicePoint.MaxIdleTime);
                Console.WriteLine ("New service point is idle since " + currentServicePoint.IdleSince );

                // Check that a new ServicePoint instance has been created.
                if (hashCode == currentHashCode)
                    Console.WriteLine ("Service point reused.");
                    Console.WriteLine ("A new service point created.") ;
            catch (Exception e)
                Console.WriteLine ("Source : " + e.Source);
                Console.WriteLine ("Message : " + e.Message);
                if (res != null)
                    res.Close ();

        // Show the user how to use this program when wrong inputs are entered.
        private static void showUsage ()
            Console.WriteLine ("Enter the proxy name as follows:");
            Console.WriteLine ("\tcs_servicepoint proxyName");

        public static void Main (string[] args)
            int port = 80;

            // Define a regular expression to parse the user's input.
            // This is a security check. It allows only
            // alphanumeric input strings between 2 to 40 characters long.
            Regex rex = new Regex (@"^[a-zA-Z]\w{1,39}$");

            if (args.Length < 1)
                showUsage ();
            string proxy = args[0];

            if ((rex.Match (proxy)).Success != true)
                Console.WriteLine ("Input string format not allowed.");
            string proxyAdd = "http://" + proxy + ":" + port;

            // Create a proxy object.  
            WebProxy DefaultProxy = new WebProxy (proxyAdd, true);

            // Set the proxy that all HttpWebRequest instances use.
            WebRequest.DefaultWebProxy = DefaultProxy;

            // Get the base interface for proxy access for the 
            // WebRequest-based classes.
            IWebProxy Iproxy = WebRequest.DefaultWebProxy;

            // Set the maximum number of ServicePoint instances to 
            // maintain. If a ServicePoint instance for that host already 
            // exists when your application requests a connection to
            // an Internet resource, the ServicePointManager object
            // returns this existing ServicePoint instance. If none exists 
            // for that host, it creates a new ServicePoint instance.
            ServicePointManager.MaxServicePoints = 4;

            // Set the maximum idle time of a ServicePoint instance to 10 seconds.
            // After the idle time expires, the ServicePoint object is eligible for
            // garbage collection and cannot be used by the ServicePointManager object.
            ServicePointManager.MaxServicePointIdleTime = 10000;

            ServicePointManager.UseNagleAlgorithm = true;
            ServicePointManager.Expect100Continue = true;
            ServicePointManager.CheckCertificateRevocationList = true;
            ServicePointManager.DefaultConnectionLimit = ServicePointManager.DefaultPersistentConnectionLimit;
            // Create the Uri object for the resource you want to access.
            Uri MS = new Uri ("");

            // Use the FindServicePoint method to find an existing 
            // ServicePoint object or to create a new one.  
            ServicePoint servicePoint = ServicePointManager.FindServicePoint (MS, Iproxy);

            ShowProperties (servicePoint);

            int hashCode = servicePoint.GetHashCode ();

            Console.WriteLine ("Service point hashcode: " + hashCode);

            // Make a request with the same scheme identifier and host fragment
            // used to create the previous ServicePoint object.
            makeWebRequest (hashCode, "");



.NET Framework
Available since 1.1

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top