WCF MaxPendingAccepts:默认值 0

Dan*_*elG 2 wcf self-hosting

根据 MSDN,如果 WCF-Service 的 MaxPendingAccepts 设置为 0,WCF 将为我们配置该值。

http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.httptransportbindingelement.maxpendingaccepts(v=vs.110).aspx

这意味着什么?是动态变化的吗?这背后的算法是什么?

Tim*_*Tim 5

我看了一下源代码System.ServiceModel.Channels.HttpTransportBindingElement。该类的默认构造函数具有以下代码行:

this.maxPendingAccepts = HttpTransportDefaults.DefaultMaxPendingAccepts;
Run Code Online (Sandbox Code Playgroud)

看一下HttpTransportsDefault显示以下代码:

// We use 0 as the default value of the MaxPendingAccepts property on HttpTransportBindingElement. In 4.5 we always
// use 10 under the hood if the default value is picked. In future releases, we could adjust the underlying default
// value when we have the dynamic expending pattern of BeginGetContext call implemented and the heap fragmentation issue
// from NCL layer solved.
const int PendingAcceptsConstant = 10;
internal const int DefaultMaxPendingAccepts = 0;
internal const int MaxPendingAcceptsUpperLimit = 100000;
internal static int GetEffectiveMaxPendingAccepts(int maxPendingAccepts)
{
    return maxPendingAccepts == HttpTransportDefaults.DefaultMaxPendingAccepts ?
                                PendingAcceptsConstant :
                                maxPendingAccepts;
}
Run Code Online (Sandbox Code Playgroud)

所以看起来如果您使用 0(默认值),您实际上会得到 10,并且您的上限为 100,000。

所以本质上,如果你将值设置为 0(或者甚至不设置它,这将导致它默认为 0)实际值将是 10。