本文介绍了当我在代码中创建NetTcpBinding时,如何设置ReliableSession.MaxPendingChannels?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们收到此错误:

根据我的理解,我需要增加ReliableSession中MaxPendingChannels的值但是我们在这样的代码中配置WCF:

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

那么如何以编程方式设置ReliableSession.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(基本绑定不+
有ReliableSessionBindingElement);
}
}

.....

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

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


We are getting this error:

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.

解决方案

This is what I did:

 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);

这篇关于当我在代码中创建NetTcpBinding时,如何设置ReliableSession.MaxPendingChannels?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 21:54