gpt4 book ai didi

.net - 在代码中创建 NetTcpBinding 时如何设置 ReliableSession.MaxPendingChannels?

转载 作者:行者123 更新时间:2023-12-01 09:39:25 27 4
gpt4 key购买 nike

我们收到此错误:

System.ServiceModel.ServerTooBusyException: The request to create a reliable session has been refused by the RM Destination. Server 'net.tcp://localhost:50000/' is too busy to process this request. Try again later. The channel could not be opened.

据我了解,我需要在 ReliableSession 绑定(bind)中增加 MaxPendingChannels 的值。

但是我们在这样的代码中配置 WCF:

serviceHost = new ServiceHost(typeof(MyServiceClass));
ServiceEndpoint endPoint = serviceHost.AddServiceEndpoint(
typeof(IMyService),
new NetTcpBinding(SecurityMode.None, true),
endPointAddress);

那么如何以编程方式设置 ReliableSession.MaxPendingChannels?(我能找到的所有示例都使用配置文件)


web page 上搜索 MaxPendingChannels对于一个选项,但它似乎过于复杂。

最佳答案

这就是我所做的:

 private Binding CreateBindingWith_MaxPendingChannels_Set(Binding baseBinding)
{
BindingElementCollection elements = baseBinding.CreateBindingElements();
ReliableSessionBindingElement reliableSessionElement =
elements.Find<ReliableSessionBindingElement>();
if (reliableSessionElement != null)
{
reliableSessionElement.MaxPendingChannels = 128;

CustomBinding newBinding = new CustomBinding(elements);

newBinding.CloseTimeout = baseBinding.CloseTimeout;
newBinding.OpenTimeout = baseBinding.OpenTimeout;
newBinding.ReceiveTimeout = baseBinding.ReceiveTimeout;
newBinding.SendTimeout = baseBinding.SendTimeout;
newBinding.Name = baseBinding.Name;
newBinding.Namespace = baseBinding.Namespace;
return newBinding;
}
else
{
throw new Exception("the base binding does not " +
"have ReliableSessionBindingElement");
}
}

.....

 Binding customBinding = CreateBindingWith_MaxPendingChannels_Set(
new NetTcpBinding(SecurityMode.None, true));

serviceHost = new ServiceHost(typeof(MyService));
ServiceEndpoint endPoint = serviceHost.AddServiceEndpoint(
typeof(IMyService),
customBinding,
endPointAddress);

关于.net - 在代码中创建 NetTcpBinding 时如何设置 ReliableSession.MaxPendingChannels?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2417496/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com