ServicePointManager 类


管理 ServicePoint 对象集合。Manages the collection of ServicePoint objects.

public ref class ServicePointManager
public class ServicePointManager
type ServicePointManager = class
Public Class ServicePointManager


下面的代码示例创建一个 ServicePoint 对象,用于连接到 URI www.contoso.comThe following code example creates a ServicePoint object for connections to the URI

Uri^ myUri = gcnew Uri( "" );
ServicePoint^ mySP = ServicePointManager::FindServicePoint( myUri );
Uri myUri = new Uri("");

ServicePoint mySP = ServicePointManager.FindServicePoint(myUri);
Dim myUri As New Uri("")
Dim mySP As ServicePoint = ServicePointManager.FindServicePoint(myUri)


ServicePointManager 是一个静态类,用来创建、维护和删除类的实例 ServicePointServicePointManager is a static class used to create, maintain, and delete instances of the ServicePoint class.

当应用程序请求连接到 Internet 资源统一资源标识符 (URI) 通过对象连接时 ServicePointManager ,将 ServicePointManager 返回一个 ServicePoint 对象,其中包含由 URI 标识的主机和方案的连接信息。When an application requests a connection to an Internet resource Uniform Resource Identifier (URI) through the ServicePointManager object, the ServicePointManager returns a ServicePoint object that contains connection information for the host and scheme identified by the URI. 如果存在 ServicePoint 该主机和方案的现有对象,则该 ServicePointManager 对象将返回现有 ServicePoint 对象; 否则,该对象会 ServicePointManager 创建一个新 ServicePoint 的对象。If there is an existing ServicePoint object for that host and scheme, the ServicePointManager object returns the existing ServicePoint object; otherwise, the ServicePointManager object creates a new ServicePoint object.

4.6 .NET Framework 包括一项新的安全功能,用于阻止连接的不安全密码和哈希算法。The .NET Framework 4.6 includes a new security feature that blocks insecure cipher and hashing algorithms for connections. 默认情况下,通过 api 使用 TLS/SSL (如、、、、等 HttpClientHttpWebRequest FtpWebRequest SmtpClient SslStream 和目标 .NET Framework 4.6 获取更安全的行为。Applications using TLS/SSL through APIs such as HttpClient, HttpWebRequest, FtpWebRequest, SmtpClient, SslStream, etc. and targeting .NET Framework 4.6 get the more-secure behavior by default.

开发人员可能需要选择退出此行为,以便与现有的 SSL3 服务或具有 RC4 服务的 TLS 保持互操作性。Developers may want to opt out of this behavior in order to maintain interoperability with their existing SSL3 services or TLS w/ RC4 services. 本文 介绍如何修改代码,以便禁用新行为。This article explains how to modify your code so that the new behavior is disabled.


不建议使用 ServicePointManager 类进行新的开发。We don't recommend that you use the ServicePointManager class for new development. 而应使用 System.Net.Http.HttpClient 类。Instead, use the System.Net.Http.HttpClient class.



在连接到 HTTP/1.0 或更高版本服务器的 ServicePoint 对象上允许存在的非持久性连接的默认数目 (4)。The default number of non-persistent connections (4) allowed on a ServicePoint object connected to an HTTP/1.0 or later server. 此字段为常量,但从 .NET Framework 2.0 开始不再使用。This field is constant but is no longer used as of .NET Framework 2.0.


在连接到 HTTP/1.1 或更高版本服务器的 ServicePoint 对象上允许存在的持久性连接的默认数目 (2)。The default number of persistent connections (2) allowed on a ServicePoint object connected to an HTTP/1.1 or later server. 如果未以直接方式或通过配置设置 DefaultConnectionLimit 属性的值,则此字段为常量,用于初始化 DefaultConnectionLimit 属性。This field is constant and is used to initialize the DefaultConnectionLimit property if the value of the DefaultConnectionLimit property has not been set either directly or through configuration.



获取或设置服务器证书的策略。Gets or sets policy for server certificates.


获取或设置一个 Boolean 值,该值指示是否根据证书颁发机构吊销列表检查证书。Gets or sets a Boolean value that indicates whether the certificate is checked against the certificate authority revocation list.


获取或设置 ServicePoint 对象所允许的最大并发连接数。Gets or sets the maximum number of concurrent connections allowed by a ServicePoint object.


获取或设置一个值,该值指示域名服务 (DNS) 解析多长时间内视为有效。Gets or sets a value that indicates how long a Domain Name Service (DNS) resolution is considered valid.


获取或设置一个值,该值指示域名服务 (DNS) 解析是否在多个适用的 Internet 协议 (IP) 地址之间轮流进行。Gets or sets a value that indicates whether a Domain Name Service (DNS) resolution rotates among the applicable Internet Protocol (IP) addresses.


获取此 ServicePointManager 实例的 EncryptionPolicyGets the EncryptionPolicy for this ServicePointManager instance.


获取或设置一个 Boolean 值,该值确定是否使用 100-Continue 行为。Gets or sets a Boolean value that determines whether 100-Continue behavior is used.


获取或设置 ServicePoint 对象的最大空闲时间。Gets or sets the maximum idle time of a ServicePoint object.


获取或设置任何时候保持的最大 ServicePoint 对象数。Gets or sets the maximum number of ServicePoint objects to maintain at any time.


将此属性值设置为 true 会导致来自 HttpWebRequest 的所有出站 TCP 连接对套接字使用本机套接字选项 SO_REUSE_UNICASTPORT。Setting this property value to true causes all outbound TCP connections from HttpWebRequest to use the native socket option SO_REUSE_UNICASTPORT on the socket. 这会导致共享基础传出端口。This causes the underlying outgoing ports to be shared. 在短时间内进行大量传出连接并且应用面临端口耗尽风险的情况下,这很有用。This is useful for scenarios where a large number of outgoing connections are made in a short time, and the app risks running out of ports.


获取或设置由 ServicePointManager 对象管理的 ServicePoint 对象所使用的安全协议。Gets or sets the security protocol used by the ServicePoint objects managed by the ServicePointManager object.


获取或设置用于验证服务器证书的回调。Gets or sets the callback to validate a server certificate.


确定由此 ServicePointManager 对象管理的服务点是否使用 Nagle 算法。Determines whether the Nagle algorithm is used by the service points managed by this ServicePointManager object.



确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
FindServicePoint(String, IWebProxy)

查找现有的 ServicePoint 对象或创建新的 ServicePoint 对象,以管理与指定的统一资源标识符 (URI) 的通信。Finds an existing ServicePoint object or creates a new ServicePoint object to manage communications with the specified Uniform Resource Identifier (URI).


查找现有的 ServicePoint 对象或创建新的 ServicePoint 对象来管理与指定 Uri 对象的通信。Finds an existing ServicePoint object or creates a new ServicePoint object to manage communications with the specified Uri object.

FindServicePoint(Uri, IWebProxy)

查找现有的 ServicePoint 对象或创建新的 ServicePoint 对象来管理与指定 Uri 对象的通信。Finds an existing ServicePoint object or creates a new ServicePoint object to manage communications with the specified Uri object.


作为默认哈希函数。Serves as the default hash function.

(继承自 Object)

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
SetTcpKeepAlive(Boolean, Int32, Int32)

对 TCP 连接启用或禁用 keep-alive 选项。Enables or disables the keep-alive option on a TCP connection.


返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)