在代码中创建 NetTcpBinding 时如何设置 ReliableSession.MaxPendingChannels?
我们收到此错误:
System.ServiceModel.ServerTooBusyException: 要求创建一个可靠的 会话已被 RM 拒绝 目的地。服务器 'net.tcp://localhost:50000/' 也是 正忙于处理此请求。尝试 稍后再来。该频道无法 打开。
据我了解,我需要增加 ReliableSession 绑定中 MaxPendingChannels 的值。
但是,我们在代码中配置 WCF 如下:
serviceHost = new ServiceHost(typeof(MyServiceClass));
ServiceEndpoint endPoint = serviceHost.AddServiceEndpoint(
typeof(IMyService),
new NetTcpBinding(SecurityMode.None, true),
endPointAddress);
那么如何以编程方式设置 ReliableSession.MaxPendingChannels? (我能找到的所有示例都使用配置文件)
在此搜索 MaxPendingChannels 网页 一个选项,但似乎过于复杂。
We are getting this error:
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.
As I understand it, I need to increase the value of MaxPendingChannels in the ReliableSession binding.
However we configure WCF in code like this:
serviceHost = new ServiceHost(typeof(MyServiceClass));
ServiceEndpoint endPoint = serviceHost.AddServiceEndpoint(
typeof(IMyService),
new NetTcpBinding(SecurityMode.None, true),
endPointAddress);
So how do I set ReliableSession.MaxPendingChannels programmatically?
(All the examples I can find use config files)
Search for MaxPendingChannels on this web page for one option, but it seems over complex.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这就是我所做的:
......
This is what I did:
.....
我还需要在代码中设置此属性,经过研究发现有两种方法可以以编程方式完成此操作。
第一种方法是直接在代码中创建绑定元素,并根据它们创建新的自定义绑定,如 CustomBinding MSDN
我发现的第二种方法是从现有绑定中获取对绑定元素的引用,如此处所述 如何:自定义系统提供的绑定。这就是最上面的答案。
我尝试在 NetTcpBinding 上设置 ReliableSession 属性,但它实际上并未修改我期望的 MaxPendingConnections 属性。在查看 NetTcpBinding 和 ReliableSession 的 .NET 源代码后,我发现像这样在绑定上设置此属性
实际上并没有在绑定上设置 MaxPendingChannels 属性。
我最终直接从绑定元素创建绑定,因为我想精确控制绑定
I also needed to set this property in code and after researching it found there are two ways to do it programmatically.
The first way is to create the binding elements directly in code, and create a new Custom Binding from them as described on the CustomBinding MSDN
the second way I found is to grab a reference to the binding elements from an existing binding as described here How to: Customize a System-Provided Binding. This is what the top answer is.
I tried to set the ReliableSession property on the NetTcpBinding, but it wasn't actually modifying the MaxPendingConnections property that I was expecting. After looking into the .NET source for NetTcpBinding and ReliableSession, I found that setting this property on the binding like this
Doesn't actually set the MaxPendingChannels property on the binding.
I ended up creating my binding from the binding elements directly since I wanted to precisely control the binding
或者,您可以使用
NetTcpBinding
中的ReliableSession
属性的构造函数,如下所示:有关详细信息,请参阅:http://msdn.microsoft.com/en-us/library/ms585454(v=vs.110).aspx
Or you could use the constructor of the
ReliableSession
property from theNetTcpBinding
like this:For more information please see: http://msdn.microsoft.com/en-us/library/ms585454(v=vs.110).aspx
如果您使用像 NetTcpRelayBinding 这样的中继绑定,您可以使用以下代码:
用法:
If you use the relay bindings like NetTcpRelayBinding, you can use following code:
Usage: