ServicePoint 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
HTTP 연결에 대한 연결 관리를 제공합니다.
public ref class ServicePoint
public class ServicePoint
type ServicePoint = class
Public Class ServicePoint
- 상속
-
ServicePoint
예제
다음 코드 예제에서는 URI www.contoso.com
연결하는 ServicePoint 개체를 만듭니다.
// 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, www.contoso.com).
// This should improve your application performance.
// Reusing service points in this way can help improve application performance.
#using <System.dll>
using namespace System;
using namespace System::Net;
using namespace System::Threading;
using namespace System::Text::RegularExpressions;
void ShowProperties( ServicePoint^ sp )
{
Console::WriteLine( "Done calling FindServicePoint()..." );
// Display the ServicePoint Internet resource address.
Console::WriteLine( "Address = {0}", sp->Address );
// Display the date and time that the ServicePoint was last
// connected to a host.
Console::WriteLine( "IdleSince = {0}", sp->IdleSince );
// 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 = {0}", sp->MaxIdleTime );
Console::WriteLine( "ConnectionName = {0}", sp->ConnectionName );
// Display the maximum number of connections allowed on this
// ServicePoint instance.
Console::WriteLine( "ConnectionLimit = {0}", sp->ConnectionLimit );
// Display the number of connections associated with this
// ServicePoint instance.
Console::WriteLine( "CurrentConnections = {0}", sp->CurrentConnections );
if ( sp->Certificate == nullptr )
Console::WriteLine( "Certificate = (null)" );
else
Console::WriteLine( "Certificate = {0}", sp->Certificate );
if ( sp->ClientCertificate == nullptr )
Console::WriteLine( "Client Certificate = (null)" );
else
Console::WriteLine( "Client Certificate = {0}", sp->ClientCertificate );
Console::WriteLine( "ProtocolVersion = {0}", sp->ProtocolVersion->ToString() );
Console::WriteLine( "SupportsPipelining = {0}", sp->SupportsPipelining );
Console::WriteLine( "UseNagleAlgorithm = {0} ", sp->UseNagleAlgorithm.ToString() );
Console::WriteLine( "Expect 100-continue = {0}", sp->Expect100Continue.ToString() );
}
void makeWebRequest( int hashCode, String^ Uri )
{
HttpWebResponse^ res = nullptr;
// 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 = dynamic_cast<HttpWebRequest^>(WebRequest::Create( Uri ));
Console::WriteLine( "\nConnecting to {0} ............", Uri );
// Get the response object.
res = dynamic_cast<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: {0}", currentHashCode );
Console::WriteLine( "New service point max idle time: {0}", currentServicePoint->MaxIdleTime );
Console::WriteLine( "New service point is idle since {0}", 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 : {0}", e->Source );
Console::WriteLine( "Message : {0}", e->Message );
}
finally
{
if ( res != nullptr )
res->Close();
}
}
// Show the user how to use this program when wrong inputs are entered.
void showUsage()
{
Console::WriteLine( "Enter the proxy name as follows:" );
Console::WriteLine( "\tcs_servicepoint proxyName" );
}
int main()
{
array<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 = gcnew Regex( "^[a-zA-Z]\\w{1,39}$" );
if ( args->Length < 2 )
{
showUsage();
return -1;
}
String^ proxy = args[ 1 ];
if ( (rex->Match(proxy))->Success != true )
{
Console::WriteLine( "Input string format not allowed." );
return -1;
}
String^ proxyAdd = String::Format( "http://{0}:{1}", proxy, port );
// Create a proxy object.
WebProxy^ DefaultProxy = gcnew 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.
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 = gcnew 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: {0}", 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/" );
}
// 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, www.contoso.com).
// 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)");
else
Console.WriteLine("Certificate = " + sp.Certificate.ToString());
if (sp.ClientCertificate == null)
Console.WriteLine("ClientCertificate = (null)");
else
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);
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();
}
}
// 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();
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.
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("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/");
}
}
}
' 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, www.contoso.com).
' Reusing service points in this way can help improve application performance.
Imports System.Net
Imports System.Threading
Imports System.Text.RegularExpressions
Namespace Mssc.Services.ConnectionManagement
Module M_TestServicePoint
Class TestServicePoint
Private Shared Sub ShowProperties(ByVal sp As ServicePoint)
Console.WriteLine("Done calling FindServicePoint")
' Display the ServicePoint Internet resource address.
Console.WriteLine(("Address = " + 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.ToString()))
Console.WriteLine(("ConnectionName = " + sp.ConnectionName))
' Display the maximum number of connections allowed on this
' ServicePoint instance.
Console.WriteLine(("ConnectionLimit = " + sp.ConnectionLimit.ToString()))
' Display the number of connections associated with this
' ServicePoint instance.
Console.WriteLine(("CurrentConnections = " + sp.CurrentConnections.ToString()))
If sp.Certificate Is Nothing Then
Console.WriteLine("Certificate = (null)")
Else
Console.WriteLine(("Certificate = " + sp.Certificate.ToString()))
End If
If sp.ClientCertificate Is Nothing Then
Console.WriteLine("ClientCertificate = (null)")
Else
Console.WriteLine(("ClientCertificate = " + sp.ClientCertificate.ToString()))
End If
Console.WriteLine("ProtocolVersion = " + sp.ProtocolVersion.ToString())
Console.WriteLine(("SupportsPipelining = " + sp.SupportsPipelining.ToString()))
Console.WriteLine("UseNagleAlgorithm = " + sp.UseNagleAlgorithm.ToString())
Console.WriteLine("Expect 100-continue = " + sp.Expect100Continue.ToString())
End Sub
Private Shared Sub makeWebRequest(ByVal hashCode As Integer, ByVal Uri As String)
Dim res As HttpWebResponse = Nothing
' 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.
Dim req As HttpWebRequest = CType(WebRequest.Create(Uri), HttpWebRequest)
Console.WriteLine((ControlChars.Lf + "Connecting to " + Uri + " ............"))
' Get the response object.
res = CType(req.GetResponse(), HttpWebResponse)
Console.WriteLine("Connected." + ControlChars.Lf)
Dim currentServicePoint As ServicePoint = req.ServicePoint
' Display new service point properties.
Dim currentHashCode As Integer = currentServicePoint.GetHashCode()
Console.WriteLine(("New service point hashcode: " + currentHashCode.ToString()))
Console.WriteLine(("New service point max idle time: " + currentServicePoint.MaxIdleTime.ToString()))
Console.WriteLine(("New service point is idle since " + currentServicePoint.IdleSince.ToString()))
' Check that a new ServicePoint instance has been created.
If hashCode = currentHashCode Then
Console.WriteLine("Service point reused.")
Else
Console.WriteLine("A new service point created.")
End If
Catch e As Exception
Console.WriteLine(("Source : " + e.Source))
Console.WriteLine(("Message : " + e.Message))
Finally
If Not (res Is Nothing) Then
res.Close()
End If
End Try
End Sub
' Show the user how to use this program when wrong inputs are entered.
Private Shared Sub showUsage()
Console.WriteLine("Enter the proxy name as follows:")
Console.WriteLine(ControlChars.Tab + "vb_servicepoint proxyName")
End Sub
' 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.
WebRequest.DefaultWebProxy = DefaultProxy
' Get the base interface for proxy access for the
' WebRequest-based classes.
Dim Iproxy As IWebProxy = WebRequest.DefaultWebProxy
' 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
End Class
End Module
End Namespace
설명
주의
WebRequest
, HttpWebRequest
, ServicePoint
및 WebClient
사용되지 않으므로 새 개발에 사용하면 안 됩니다. 대신 HttpClient 사용합니다.
ServicePoint 클래스는 리소스의 URI(Uniform Resource Identifier)에 전달된 호스트 정보를 기반으로 인터넷 리소스에 대한 연결을 처리합니다. 리소스에 대한 초기 연결은 ServicePoint 개체가 유지 관리하는 정보를 결정하며, 이 정보는 해당 리소스에 대한 모든 후속 요청에서 공유됩니다.
ServicePoint 개체는 ServicePointManager 클래스에서 관리되며 필요한 경우 ServicePointManager.FindServicePoint 메서드에 의해 만들어집니다. ServicePoint 개체는 직접 만들어지지 않지만 항상 ServicePointManager 클래스에서 만들고 관리합니다. 만들 수 있는 ServicePoint 개체의 최대 수는 ServicePointManager.MaxServicePoints 속성에 의해 설정 됩니다.
각 ServicePoint 개체는 MaxIdleTime 속성에 지정된 시간보다 오래 유휴 상태가 될 때까지 인터넷 리소스에 대한 연결을 유지합니다. ServicePoint MaxIdleTime 값을 초과하면 다른 연결로 재활용할 수 있습니다. MaxIdleTime 기본값은 ServicePointManager.MaxServicePointIdleTime 속성에 의해 설정됩니다.
ConnectionLeaseTimeout 속성이 -1이 아닌 값으로 설정되고 지정된 시간이 경과하면 다음 요청을 처리한 후 활성 ServicePoint 연결이 닫힙니다. 이는 기본적으로 무한정 열려 있는 활성 연결이 필요하지 않은 애플리케이션에 유용합니다.
메모
부하가 높은 조건에서 일부 애플리케이션은 ThreadPool에서 사용 가능한 스레드가 부족하여 시스템 성능이 저하될 수 있습니다(예: 높음 및 가변 트랜잭션 시간).
속성
Address |
이 ServicePoint 개체가 연결하는 서버의 URI(Uniform Resource Identifier)를 가져옵니다. |
BindIPEndPointDelegate |
로컬 IPEndPointServicePoint연결할 대리자를 지정합니다. |
Certificate |
이 ServicePoint 개체에 대해 받은 인증서를 가져옵니다. |
ClientCertificate |
서버에 마지막으로 전송된 클라이언트 인증서를 가져옵니다. |
ConnectionLeaseTimeout |
활성 ServicePoint 연결이 닫힌 후의 시간(밀리초)을 가져오거나 설정합니다. |
ConnectionLimit |
이 ServicePoint 개체에 허용되는 최대 연결 수를 가져오거나 설정합니다. |
ConnectionName |
연결 이름을 가져옵니다. |
CurrentConnections |
이 ServicePoint 개체와 연결된 열린 연결 수를 가져옵니다. |
Expect100Continue |
100-Continue 동작이 사용되는지 여부를 결정하는 Boolean 값을 가져오거나 설정합니다. |
IdleSince |
ServicePoint 개체가 호스트에 마지막으로 연결된 날짜와 시간을 가져옵니다. |
MaxIdleTime |
연결이 닫히기 전에 ServicePoint 개체와 연결된 연결이 유휴 상태로 유지될 수 있는 시간을 가져오거나 설정합니다. |
ProtocolVersion |
ServicePoint 개체에서 사용하는 HTTP 프로토콜의 버전을 가져옵니다. |
ReceiveBufferSize |
이 ServicePoint사용되는 소켓의 수신 버퍼 크기를 가져오거나 설정합니다. |
SupportsPipelining |
ServicePoint 개체가 파이프라인 연결을 지원하는지 여부를 나타냅니다. |
UseNagleAlgorithm |
이 ServicePoint 개체에서 관리하는 연결에서 Nagle 알고리즘이 사용되는지 여부를 결정하는 Boolean 값을 가져오거나 설정합니다. |
메서드
CloseConnectionGroup(String) |
이 ServicePoint 개체에서 지정된 연결 그룹을 제거합니다. |
Equals(Object) |
지정된 개체가 현재 개체와 같은지 여부를 확인합니다. (다음에서 상속됨 Object) |
GetHashCode() |
ServicePoint 인스턴스의 해시 값을 반환합니다. |
GetHashCode() |
기본 해시 함수로 사용됩니다. (다음에서 상속됨 Object) |
GetType() |
현재 인스턴스의 Type 가져옵니다. (다음에서 상속됨 Object) |
MemberwiseClone() |
현재 Object단순 복사본을 만듭니다. (다음에서 상속됨 Object) |
SetTcpKeepAlive(Boolean, Int32, Int32) |
TCP 연결에서 연결 유지 옵션을 사용하거나 사용하지 않도록 설정합니다. |
ToString() |
현재 개체를 나타내는 문자열을 반환합니다. (다음에서 상속됨 Object) |
적용 대상
.NET