我正在使用WCF进行IPC。只有一台服务器和一个客户端,都是.Net3.5并且在同一台机器上运行,没有升级,没有任何系统设置改变(正常使用下)。
这在所有客户端(从WinXp到Win8)都没有问题。但是,在大约20分钟的通信之后,只有一台机器在客户端应用程序中出现TimeoutException
。此行为无法在其他位置复制,但每次都以相同的方式在客户端中复制。在应用程序生命周期中,正在进行多次调用,至少我会说几百次。堆栈位于问题的底部。
服务合约
[ServiceContract]
interface IExampleService
{
[OperationContract]
string TestSample();
}
服务合同实施
[ServiceBehavior(IncludeExceptionDetailInFaults = true,
InstanceContextMode = InstanceContextMode.Single)]
internal class ExampleService : IExampleService
{
// IExampleService implementation
}
服务器初始化(始终在客户端之前启动)
// Server initialization
Uri baseAddress = new Uri("net.pipe://127.0.0.1/Example");
NetNamedPipeBinding binding = new NetNamedPipeBinding();
var service = new ExampleService();
ServiceHost serviceHost = new ServiceHost(service, baseAddress);
serviceHost.AddServiceEndpoint(typeof(IExampleService), binding, baseAddress);
serviceHost.Open();
客户端初始化
// Client initialization
EndpointAddress address = new EndpointAddress(new Uri("net.pipe://127.0.0.1/Example"));
NetNamedPipeBinding binding = new NetNamedPipeBinding();
ChannelFactory<IExampleService> factory = new ChannelFactory<IExampleService>(binding, address);
IExampleService exampleService = factory.CreateChannel();
这是客户端上的堆栈(手头唯一的线索):
serverResponseWorker_DoWork System.TimeoutException: The open operation did not complete within the allotted timeout of 00:01:00. The time allotted to this operation may have been a portion of a longer timeout.
at System.ServiceModel.Channels.PipeConnection.WaitForSyncRead(TimeSpan timeout, Boolean traceExceptionsAsErrors)
at System.ServiceModel.Channels.PipeConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
at System.ServiceModel.Channels.DelegatingConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
at System.ServiceModel.Channels.ConnectionUpgradeHelper.InitiateUpgrade(StreamUpgradeInitiator upgradeInitiator, IConnection& connection, ClientFramingDecoder decoder, IDefaultCommunicationTimeouts defaultTimeouts, TimeoutHelper& timeoutHelper)
at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.SendPreamble(IConnection connection, ArraySegment`1 preamble, TimeoutHelper& timeoutHelper)
at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.DuplexConnectionPoolHelper.AcceptPooledConnection(IConnection connection, TimeoutHelper& timeoutHelper)
at System.ServiceModel.Channels.ConnectionPoolHelper.EstablishConnection(TimeSpan timeout)
at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.OnOpen(TimeSpan timeout)
--- End of inner exception stack trace ---
Server stack trace:
at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel channel, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout, CallOnceManager cascade)
at System.ServiceModel.Channels.ServiceChannel.EnsureOpened(TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
服务器应用程序在客户端上的异常之后继续运行,并且服务器似乎没有抛出任何异常。省略了一些细节,请询问是否需要其他东西。
可能导致这种情况的原因是什么?我很确定它是在特定的机器上,否则我们很幸运能在几百个客户端运行。
答案 0 :(得分:1)
客户端未收到服务器的响应,因此会发生超时
答案 1 :(得分:0)
NetNamedPipeBinding binding = new NetNamedPipeBinding();
CustomBinding pipeBinding = new CustomBinding(binding);
pipeBinding.Elements.Find<NamedPipeTransportBindingElement>().ConnectionPoolSettings.IdleTimeout = TimeSpan.MaxValue;
binding.ReceiveTimeout = TimeSpan.MaxValue;
只需添加超时