zz WCF客户端无法访问服务原因之二:连接数问题

如果出现以下错误信息,极有可能是连接数过多,WCF配置文件默认为10个连接数,如果连接服务的客户端超过10个后,将访问不到服务.信息如下:

System.TimeoutException: 请求通道在等待 00:01:00 以后答复时超时。增加传递给请求调用的超时值,或者增加绑定上的 SendTimeout 值。分配给此操作的时间可能是更长超时的一部分。 ---> System.TimeoutException: 对“http://localhost:8731/WCFTest/Service1/”的 HTTP 请求已超过为 00:01:00 分配的超时。为此操作分配的时间可能是较长超时的一部分。 ---> System.Net.WebException: 操作超时
在 System.Net.HttpWebRequest.GetResponse()
在 System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
--- 内部异常堆栈跟踪的结尾 ---
在 System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
在 System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
在 System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
--- 内部异常堆栈跟踪的结尾 ---

Server stack trace: 
在 System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
在 System.ServiceModel.Channels.ClientReliableChannelBinder`1.RequestClientReliableChannelBinder`1.OnRequest(TRequestChannel channel, Message message, TimeSpan timeout, MaskingMode maskingMode)
在 System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout, MaskingMode maskingMode)
在 System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout)
在 System.ServiceModel.Security.SecuritySessionClientSettings`1.SecurityRequestSessionChannel.Request(Message message, TimeSpan timeout)
在 System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
在 System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
在 System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
在 System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
在 System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
在 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
在 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
在 WCFClient.ServiceReference1.IService1.DoWork(String str)
在 WCFClient.ServiceReference1.Service1Client.DoWork(String str) 位置 F:\sss\WCFTest\WCFClient]\Service References\ServiceReference1\Reference.cs:行号 50
在 WCFClient.Program.Main(String[] args) 位置 F:\sss\WCFTest\WCFClient]\Program.cs:行号 19

解决方案:
1)首先保证客户端每次建立的连接在使用完成后进行关闭.即调用Close()方法,否则此连接会在设置的会话(一般为10分钟)后才自动关闭.期间任何客户端也无法使用此服务.
2)如果默认的连接数不能满足客户端的需要,可以增加连接数.配置文件如下:
<serviceThrottling maxConcurrentCalls="20" maxConcurrentSessions="20" maxConcurrentInstances="30" />
说明:maxConcurrentCalls :最大并发数,默认为16 
maxConcurrentSessions :最大的会话数,主要针对于PerSession的情况,默认为10 
maxConcurrentInstances:最大实例数,默认为26

posted on 2017-07-27 12:39  oyl  阅读(221)  评论(0编辑  收藏  举报

导航