Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
FindServicePoint Method (String, IWebProxy)

ServicePointManager.FindServicePoint Method (String, IWebProxy)

Finds an existing ServicePoint object or creates a new ServicePoint object to manage communications with the specified Uniform Resource Identifier (URI).

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

'Declaration
Public Shared Function FindServicePoint ( _
	uriString As String, _
	proxy As IWebProxy _
) As ServicePoint
'Usage
Dim uriString As String
Dim proxy As IWebProxy
Dim returnValue As ServicePoint

returnValue = ServicePointManager.FindServicePoint(uriString, proxy)
public static ServicePoint FindServicePoint (
	String uriString, 
	IWebProxy proxy
)
public static function FindServicePoint (
	uriString : String, 
	proxy : IWebProxy
) : ServicePoint

Parameters

uriString

The URI of the Internet resource to be contacted.

proxy

The proxy data for this request.

Return Value

The ServicePoint object that manages communications for the request.

Exception typeCondition

UriFormatException

The URI specified in uriString is invalid.

InvalidOperationException

The maximum number of ServicePoint objects defined in MaxServicePoints has been reached.

The FindServicePoint method returns the ServicePoint object associated with the specified Internet host name. If no ServicePoint object exists for that host, the ServicePointManager object creates one.

The following code example demonstrates calling this method to access a ServicePoint object.

' This is the program entry point. It allows the user to enter 
' a server name that is used to locate its current homepage.
Public Shared Sub Main(ByVal args() As String)
    Dim proxy As String = Nothing
    Dim port As Integer = 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.
    Dim rex As New Regex("^[a-zA-Z]\w{1,39}$")

    If args.Length = 0 Then
        ' Show how to use this program.
        showUsage()
        Return
    End If

    proxy = args(0)
    If (Not (rex.Match(proxy)).Success) Then
        Console.WriteLine("Input string format not allowed.")
        Return
    End If

    ' Create a proxy object.  
    Dim proxyAdd As String
    proxyAdd = "http://" + proxy + ":" + port.ToString()


    Dim DefaultProxy As New WebProxy(proxyAdd, True)

    ' Set the proxy that all HttpWebRequest instances use.
    GlobalProxySelection.Select = DefaultProxy

    ' Get the base interface for proxy access for the 
    ' WebRequest-based classes.
    Dim Iproxy As IWebProxy = GlobalProxySelection.Select

    ' Set the maximum number of ServicePoint instances to maintain.
    ' Note that, 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. 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.
    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.
    Dim MS As New Uri("http://msdn.microsoft.com/")

    ' Use the FindServicePoint method to find an existing 
    ' ServicePoint object or to create a new one.   
    Dim servicePoint As ServicePoint = ServicePointManager.FindServicePoint(MS, Iproxy)
    ShowProperties(servicePoint)
    Dim hashCode As Integer = servicePoint.GetHashCode()
    Console.WriteLine(("Service point hashcode: " + hashCode.ToString()))

    ' Make a request with the same scheme identifier and host fragment
    ' used to create the previous ServicePoint object.
    makeWebRequest(hashCode, "http://msdn.microsoft.com/library/")

End Sub 'Main


public static void main(String[] args) throws InterruptedException
{
    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();
        return;
    }

    String proxy = args[0];

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

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

    // Set the proxy that all HttpWebRequest instances use.
    GlobalProxySelection.set_Select(defaultProxy);

    // Get the base interface for proxy access for the 
    // WebRequest-based classes.
    IWebProxy iProxy = GlobalProxySelection.get_Select();

    // 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.set_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.set_MaxServicePointIdleTime(10000);

    ServicePointManager.set_UseNagleAlgorithm(true);
    ServicePointManager.set_Expect100Continue(true);
    ServicePointManager.set_CheckCertificateRevocationList(true);
    ServicePointManager.set_DefaultConnectionLimit(
        ServicePointManager.DefaultPersistentConnectionLimit);

    // Create the Uri object for the resource you want to access.
    Uri ms = new Uri("http://msdn.microsoft.com/");

    // 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, "http://msdn.microsoft.com/library/");
} //main 

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