BasicHttpBinding.MaxBufferSize BasicHttpBinding.MaxBufferSize BasicHttpBinding.MaxBufferSize BasicHttpBinding.MaxBufferSize Property

定义

获取或设置最大大小,以字节为单位,从通道接收消息的缓冲区。Gets or sets the maximum size, in bytes, for a buffer that receives messages from the channel.

public:
 property int MaxBufferSize { int get(); void set(int value); };
public int MaxBufferSize { get; set; }
member this.MaxBufferSize : int with get, set
Public Property MaxBufferSize As Integer

属性值

指定为采用此绑定配置的终结点处理消息时,存储消息的缓冲区的最大大小(以字节为单位)。The maximum size, in bytes, of a buffer that stores messages while they are processed for an endpoint configured with this binding. 默认值为 65,536 字节。The default value is 65,536 bytes.

示例

下面的示例设置MaxBufferSize为 1,000,000 字节。The following example sets MaxBufferSize to 1,000,000 bytes.

BasicHttpBinding binding = new BasicHttpBinding();

// set to one million
binding.MaxBufferSize = 1000000;

也可以在配置文件中设置此属性的值。The value of this property can also be set in the configuration file.

注解

如果缓冲区中的内存不足以在处理消息的同时对其进行存储,则必须从 CLR 堆分配更多内存,而这会增加垃圾回收的系统开销。If there is not sufficient memory in the buffer to store the message while it is processed, more memory must be allocated from the CLR heap, which increases the garbage collection overhead. 从 CLR 垃圾堆进行大量分配表明消息缓冲区太小,可以通过实现更大的内存分配来提高性能。Extensive allocation from the CLR garbage heap is an indication that the message buffer size is too small and that performance can be improved with a larger allocation.

MaxBufferSize 属性和其意义的值会不同,具体取决于是否对消息进行缓冲还是流上它们收到通过该通道:The value of the MaxBufferSize property and its significance is different depending on whether the messages are being buffered or streamed on the channel through which they are being received:

此处对缓冲区大小所设置的限制是为了优化消息交换的性能。The limitations on buffer size set here are for optimizing the performance of message exchanges. 如果消息超过为缓冲区设置的最大值,则不会丢弃该消息。If a message exceeds the maximum value set for the buffer, it is not dropped. 相反,如果从 CLR 堆请求更多的内存,这将带来比使用缓冲区更多的垃圾回收系统开销。Instead, more memory is requested from the CLR heap and this incurs more garbage collection overhead than using the buffers.

备注

MaxBufferSize 和 MaxReceivedMessageSize 的设置都是本地行为设置。The settings for MaxBufferSize and MaxReceivedMessageSize, are local behavioral settings. 这表示它们不会传输到元数据中的其他终结点。This means that they are not transmitted to other endpoints in metadata. 如果为元数据中一个最大消息大小为 2GB 的服务生成了一个代理,则该代理的最大消息大小仍为默认的 64K。If you generate a proxy to a service with a maximum message size of 2GB from metadata, the proxy still has a default value of 64K. 这样就使对消息和消息缓冲区大小进行适当限制的控制权处在本地管理员的管辖范围内。This leaves control of the appropriate bounds for message and message buffer size in the scope of local administrators.

适用于