0

我正在为 IPC 使用 WCF。只有一个服务器和一个客户端,.Net3.5 和在同一台机器上运行,没有提升,没有任何系统设置更改(在正常使用下)。

这在所有客户端(从 WinXp 到 Win8)中都可以正常运行。但只有在一台机器上TimeoutException,在大约 20 分钟的通信后,客户端应用程序中才会出现 a。此行为无法在其他地方复制,但每次都以相同的方式在客户端中复制。在应用程序生命周期中,有几个调用被打了,我会说至少有几百个。堆栈位于问题的底部。

服务合同

[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)

服务器应用程序在客户端发生异常后继续运行,并且服务器似乎没有抛出任何异常。一些细节被省略了,请询问是否需要其他内容。

这可能是什么原因造成的?我很确定它在特定的机器上,否则我们真的很幸运能在数百个客户端上运行它。

4

2 回答 2

1

客户端没有得到服务器的响应,所以会发生超时

  • 检查服务器端是否发生任何异常
于 2013-06-06T10:16:45.213 回答
0
       NetNamedPipeBinding binding = new NetNamedPipeBinding();
            CustomBinding pipeBinding = new CustomBinding(binding);
pipeBinding.Elements.Find<NamedPipeTransportBindingElement>().ConnectionPoolSettings.IdleTimeout = TimeSpan.MaxValue;
            binding.ReceiveTimeout = TimeSpan.MaxValue;

只需要添加超时

于 2013-06-06T10:03:51.257 回答