本文的目的是想让各位同道通过在windows操作系统上通过启动exe程序实现进程间通信(局域网或者互联网都可实现),NetTCP绑定方式如下
-
首先必须打开服务器上的NetTCP Port Sharing Service
-
然后通过如下方式进行绑定
private Binding CreateNetTcpBinding(AppNetworkConnectionProxy serviceProxy)
{
NetTcpBinding defaultTcpBinding = new NetTcpBinding(SecurityMode.None);
defaultTcpBinding.PortSharingEnabled = true;
defaultTcpBinding.MaxReceivedMessageSize = int.MaxValue;
defaultTcpBinding.MaxConnections = serviceProxy.MaxConnections;
defaultTcpBinding.ReaderQuotas.MaxArrayLength = serviceProxy.ReaderQuotas;
defaultTcpBinding.ReaderQuotas.MaxBytesPerRead = serviceProxy.ReaderQuotas;
defaultTcpBinding.ReaderQuotas.MaxStringContentLength = serviceProxy.ReaderQuotas;int bufferPoolSize = serviceProxy.MaxBufferPoolSize * 1024;// KB size buffer defaultTcpBinding.MaxBufferPoolSize = Math.Max(bufferPoolSize, defaultTcpBinding.MaxBufferPoolSize); // Only enable reliable session when idletimeout set in event based channel. // ACHEN : I don't understand this if (serviceProxy.InactivityTimeout != TimeSpan.Zero) { defaultTcpBinding.ReliableSession.Enabled = true; defaultTcpBinding.ReliableSession.InactivityTimeout = serviceProxy.InactivityTimeout; } BindingElementCollection bindingElementCollection = defaultTcpBinding.CreateBindingElements(); TcpTransportBindingElement bindingElement = bindingElementCollection.Find<TcpTransportBindingElement>(); bindingElement.ConnectionBufferSize = serviceProxy.SocketBufferSize; // todo : why create a new one? CustomBinding customTcpBinding = new CustomBinding(bindingElementCollection); customTcpBinding.SendTimeout = serviceProxy.SendTimeout; customTcpBinding.ReceiveTimeout = serviceProxy.ReceiveTimeout; customTcpBinding.CloseTimeout = serviceProxy.CloseTimeout; customTcpBinding.OpenTimeout = serviceProxy.OpenTimeout; return customTcpBinding; }