Odys
Odys

Reputation: 9090

WCF client throws System.TimeoutException after 20mins

I'm using WCF for IPC. There is a server and single client only, both .Net3.5 and run on the same machine, not elevated, without any system settings altered (under normal use).

This runs without issue in all clients (from WinXp to Win8). But only in one machine a TimeoutException occurs in the client application after around 20 minutes of communication. This behavior cannot be replicated elsewhere but is being replicate in the client the same way every time. During the application lifetime several calls are being made, I would say around hundred at least. The stack is at the bottom of the question.

The service contract

[ServiceContract]
interface IExampleService
{
    [OperationContract]
    string TestSample();
}

service contract implementation

[ServiceBehavior(IncludeExceptionDetailInFaults = true,
                 InstanceContextMode = InstanceContextMode.Single)]
internal class ExampleService : IExampleService
{
    // IExampleService implementation
}

Server initialization (Always starts before client)

// 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

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

Here is the stack on the client (the only clue in hand):

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)

The server application continues running after the exception on the client and the server doesn't seem to throw any exceptions. Several details have been omitted, please ask if something else is needed.

What might be causing this? I'm pretty sure it's on the specific machine, otherwise we are really lucky to have this run in several hundred clients.

Upvotes: 0

Views: 2071

Answers (2)

Vikram Bose
Vikram Bose

Reputation: 3375

Client didn't get a reponse form the server so, time out will occur

  • check the server side any Exception occur

Upvotes: 1

Taj
Taj

Reputation: 1728

       NetNamedPipeBinding binding = new NetNamedPipeBinding();
            CustomBinding pipeBinding = new CustomBinding(binding);
pipeBinding.Elements.Find<NamedPipeTransportBindingElement>().ConnectionPoolSettings.IdleTimeout = TimeSpan.MaxValue;
            binding.ReceiveTimeout = TimeSpan.MaxValue;

Just need to add time outs

Upvotes: 0

Related Questions