次の方法で共有


ServicePointManager.FindServicePoint メソッド

要求を処理するための通信を管理するには、既存の ServicePoint を検出するか、新しい ServicePoint を作成します。

オーバーロードの一覧

指定した Uri との通信を管理するには、既存の ServicePoint を検出するか、新しい ServicePoint を作成します。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Shared Function FindServicePoint(Uri) As ServicePoint

[C#] public static ServicePoint FindServicePoint(Uri);

[C++] public: static ServicePoint* FindServicePoint(Uri*);

[JScript] public static function FindServicePoint(Uri) : ServicePoint;

指定した URI との通信を管理するには、既存の ServicePoint を検出するか、新しい ServicePoint を作成します。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Shared Function FindServicePoint(String, IWebProxy) As ServicePoint

[C#] public static ServicePoint FindServicePoint(string, IWebProxy);

[C++] public: static ServicePoint* FindServicePoint(String*, IWebProxy*);

[JScript] public static function FindServicePoint(String, IWebProxy) : ServicePoint;

指定した Uri インスタンスとの通信を管理するには、既存の ServicePoint を検出するか、新しい ServicePoint を作成します。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Shared Function FindServicePoint(Uri, IWebProxy) As ServicePoint

[C#] public static ServicePoint FindServicePoint(Uri, IWebProxy);

[C++] public: static ServicePoint* FindServicePoint(Uri*, IWebProxy*);

[JScript] public static function FindServicePoint(Uri, IWebProxy) : ServicePoint;

使用例

[Visual Basic, C#, C++] このメソッドを呼び出して ServicePoint インスタンスにアクセスする例を次に示します。

[Visual Basic, C#, C++] メモ   ここでは、FindServicePoint のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。

 
' 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 = 1000


    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("https://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, "https://msdn.microsoft.com/library/")

End Sub 'Main


[C#] 
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 ();
        return;
    }
    string proxy = args[0];

    if ((rex.Match (proxy)).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.Select = DefaultProxy;

    // Get the base interface for proxy access for the 
    // WebRequest-based classes.
    IWebProxy Iproxy = GlobalProxySelection.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.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 = 1000;



    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 ("https://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, "https://msdn.microsoft.com/library/");


    
}


[C++] 
void  main() 
{
    String* args[] = Environment::GetCommandLineArgs();

    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(S"^[a-zA-Z]\\w{1,39}$");

    if (args->Length < 2)
    {
        showUsage();
        return;
    }

    String* proxy = args[1];
    if ((rex->Match(proxy))->Success != true)
    {
        Console::WriteLine(S"Input string format not allowed.");
        return;
    }
    String* proxyAdd = String::Format( S"http://{0}:{1}", proxy, __box(port));
    // Create a proxy object.  
    WebProxy* DefaultProxy = 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.
    IWebProxy* Iproxy = GlobalProxySelection::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::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 = 1000;


    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(S"https://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(S"Service point hashcode: {0}", __box(hashCode));

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

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

参照

ServicePointManager クラス | ServicePointManager メンバ | System.Net 名前空間