我通过nettcpbinding使用双工通道(即点对点通信)使用应用程序托管的WCF服务编写本地机器客户端/服务器应用程序。由于遗留原因,这是.NET 3.5。
此代码设置服务器:
var netTcpBinding = new NetTcpBinding(SecurityMode.Transport);
netTcpBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
netTcpBinding.Security.Transport.ProtectionLevel = ProtectionLevel.EncryptAndSign;
netTcpBinding.ReceiveTimeout = new TimeSpan(0, 0, 14);
netTcpBinding.SendTimeout = new TimeSpan(0, 0, 30);
netTcpBinding.OpenTimeout = new TimeSpan(0, 0, 30);
netTcpBinding.CloseTimeout = new TimeSpan(0, 0, 30);
netTcpBinding.ListenBacklog = 2;
netTcpBinding.MaxConnections = 200;
netTcpBinding.MaxBufferPoolSize = 10 * 1000 * 1000;
netTcpBinding.MaxBufferSize = 10* 1000 * 1000;
netTcpBinding.MaxReceivedMessageSize = 10* 1000 * 1000;
netTcpBinding.PortSharingEnabled = true;
netTcpBinding.ReliableSession.Enabled = true;
netTcpBinding.ReliableSession.Ordered = true;
netTcpBinding.ReliableSession.InactivityTimeout = new TimeSpan(23, 59, 59);
ISmartBrowserClientServiceCallback callback = new SmartBrowserClientServiceCallback();
InstanceContext context = new InstanceContext(callback);
smartBrowserServiceFactory = new DuplexChannelFactory<ClientService.ISmartBrowserClientService>(
context,
netTcpBinding,
new EndpointAddress(uri));
this.channel = this.smartBrowserServiceFactory.CreateChannel();
此代码设置客户端:
var netTcpBinding = new NetTcpBinding(SecurityMode.Transport);
netTcpBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
netTcpBinding.Security.Transport.ProtectionLevel = ProtectionLevel.EncryptAndSign;
netTcpBinding.ReceiveTimeout = new TimeSpan(23, 59, 59);
netTcpBinding.OpenTimeout = new TimeSpan(0, 0, 15); // timeout seconds are different to help debugging
netTcpBinding.SendTimeout = new TimeSpan(0, 0, 17);
netTcpBinding.ReceiveTimeout = new TimeSpan(0, 0, 19);
netTcpBinding.CloseTimeout = new TimeSpan(0, 0, 21);
netTcpBinding.ListenBacklog = 2;
netTcpBinding.MaxConnections = 100;
netTcpBinding.MaxBufferPoolSize = 10 * 1000 * 1000;
netTcpBinding.MaxBufferSize = 10 * 1000 * 1000;
netTcpBinding.MaxReceivedMessageSize = 10 * 1000 * 1000;
netTcpBinding.PortSharingEnabled = true;
netTcpBinding.ReliableSession.Enabled = true;
netTcpBinding.ReliableSession.Ordered = true;
netTcpBinding.ReliableSession.InactivityTimeout = new TimeSpan(23, 59, 59);
ISmartBrowserClientServiceCallback callback = new SmartBrowserClientServiceCallback(this.smartBrowserClient);
InstanceContext context = new InstanceContext(callback);
this.smartBrowserServiceFactory = new DuplexChannelFactory<ISmartBrowserClientService>(
context,
netTcpBinding,
new EndpointAddress(new Uri(string.Format(CultureInfo.InvariantCulture, "net.tcp://localhost:{0}/Cpy.SmartBrowser.SmartBrowserClientService/", defaultPort.ToString(CultureInfo.InvariantCulture)))));
this.smartBrowserServiceFactory.Faulted += (sender, e) =>
{
this.smartBrowserServiceFactory = null;
};
this.channel = this.smartBrowserServiceFactory.CreateChannel();
现在,当客户端使用某些数据调用服务方法时,该服务会很好地接收该数据,该服务会对其起作用,但由于某种原因,17秒后发件人会发现TimeoutException
,我为SendTimeout
选择的值。我发现这很奇怪,因为所有要发送的数据都已经立即发送,我认为系统没有理由等待任何事情。
此客户端/服务器应用程序将在具有单个服务和单个客户端的本地计算机上使用,只是对等通信。但如果我无法摆脱这种超时,我将不得不以肮脏的方式解决这个问题,我想避免这种做法。
我遗失了哪些明显的东西?