Export (0) Print
Expand All

HttpWebRequest.ServicePoint Property

Gets the service point to use for the request.

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

public ServicePoint ServicePoint { get; }
/** @property */
public ServicePoint get_ServicePoint ()

public function get ServicePoint () : ServicePoint

Property Value

A ServicePoint that represents the network connection to the Internet resource.

The ServicePoint.Address property may be different from HttpWebRequest.Address if the request is redirected.

Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows CE Platform Note: This property is a null reference (Nothing in Visual Basic) until the request is sent because of the additional network transmission required.

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);
    try
    {
        // 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.");
        else
            Console.WriteLine ("A new service point created.") ;
    }
    catch (Exception e)
    {
        Console.WriteLine ("Source : " + e.Source);
        Console.WriteLine ("Message : " + e.Message);
    }
    finally
    {
        if (res != null)
            res.Close ();
    }
}


private static void MakeWebRequest(int hashCode, String uri) 
    throws InterruptedException
{
    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);
    try {
        // 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.get_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.get_MaxIdleTime()));
        Console.WriteLine(("New service point is idle since " 
            + currentServicePoint.get_IdleSince()));

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

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2015 Microsoft