【发布时间】:2010-12-14 21:36:41
【问题描述】:
我有一段代码调用托管在服务器上的 WCF 服务。
代码不断循环,一遍又一遍地调用这个方法。 (它要求一个“状态”,所以它根本没有做任何工作)。
没关系,只是在短时间内我收到错误消息:
发送到 net.tcp://serverName:9001/service1 的请求操作在配置的超时 (00:00:09.9843754) 内没有收到回复
突然间我根本无法访问服务器。我将超时时间增加到 1 分钟,但仍然是同样的问题。请注意,托管服务的程序没有做任何其他事情,只是提供它的“状态”。因此,WCF 服务应用程序繁忙不是问题。
我认为调用服务的代码有问题,因为当我重新启动应用程序时,它可以很好地连接到服务......直到又过了一小段时间我再次收到超时错误。出于这个原因,我也不认为这是网络错误,因为当我重新启动应用程序时,它会在一段时间内正常。
这是我用来调用服务的代码。我需要在每次调用后处理 ChannelFactory 以清理它还是我在做什么?
NetTcpBinding binding = new NetTcpBinding(SecurityMode.Message);
binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
EndpointAddress endPoint = new EndpointAddress(new Uri(clientPath));
ChannelFactory<IClient> channel = new ChannelFactory<IClient>(binding, endPoint);
channel.Faulted += new EventHandler(channel_Faulted);
IClient client = channel.CreateChannel();
((IContextChannel)client).OperationTimeout = new TimeSpan(0, 0, 10);
ClientStatus clientStatus = client.GetStatus();
【问题讨论】: