是否可以通过IEndpointBehavior实现更改ConnectionOrientedTransportBindingElement(例如ConnectionBufferSize)的属性值?
var host = new ServiceHost(typoef(ISomeService), new Uri(service));
var endpoint = host.AddServiceEndpoint(typeof (ISomeService), new NetTcpBinding(), string.Empty);
endpoint.Behaviors.Add(new MyCustomEndpointBehavior());
// ...
class MyCustomEndpointBehavior : IEndpointBehavior {
// ....
public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters) {
// what to do here?
}
}
答案 0 :(得分:1)
您不能使用行为来修改绑定内部。您需要通过配置或代码
构建自定义绑定 <customBinding>
<binding name="MyCustomBinding">
<binaryMessageEncoding />
<tcpTransport connectionBufferSize="256192" maxOutputDelay="00:00:30" transferMode="Streamed">
</tcpTransport>
</binding>
</customBinding>
或代码
var host = new ServiceHost(typeof(Service1), new Uri("net.tcp://someservice"));
//binding stack - order matters!
var myCustomNetTcpBindingStack = new List<BindingElement>();
//session - if reliable
var session = new ReliableSessionBindingElement();
myCustomNetTcpBindingStack.Add(session);
//transaction flow
myCustomNetTcpBindingStack.Add(new TransactionFlowBindingElement(TransactionProtocol.OleTransactions));
//encoding
myCustomNetTcpBindingStack.Add(new BinaryMessageEncodingBindingElement());
//security
//var security = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
//myCustomNetTcpBindingStack.Add(security);
//transport
var transport = new TcpTransportBindingElement();
transport.ConnectionBufferSize = 64 * 1024;
myCustomNetTcpBindingStack.Add(transport);
var myCustomNetTcpBinding = new CustomBinding(myCustomNetTcpBindingStack);
host.AddServiceEndpoint(typeof(IService1), myCustomNetTcpBinding, string.Empty);
host.Open();
关于ConnectionBufferSize here
的好帖子