我已经看到了以下问题和他们的非工作答案。
我有一个控制台应用程序,我正在测试我的WCF服务。当我对该服务进行80多个同时调用时,有时它可以正常工作,有时一些调用会因以下异常而失败。
异常类型: System.Net.Sockets.SocketException,System,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089
消息:由于线程退出或应用程序请求,I / O操作已中止
堆栈跟踪:
at System.ServiceModel.Channels.SocketConnection.HandleReceiveAsyncCompleted()
at System.ServiceModel.Channels.SocketConnection.OnReceiveAsync(Object sender,SocketAsyncEventArgs eventArgs)
at System.ServiceModel.Channels.SocketConnection.OnReceiveAsyncCompleted(Object sender,SocketAsyncEventArgs e)
at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(SocketAsyncEventArgs e)
at System.Net.Sockets.SocketAsyncEventArgs.FinishOperationAsyncFailure(SocketError socketError,Int32 bytesTransferred,SocketFlags flags)
在System.Net.Sockets.SocketAsyncEventArgs.CompletionPortCallback(UInt32 errorCode,UInt32 numBytes,NativeOverlapped * nativeOverlapped)
在System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode,UInt32 numBytes,NativeOverlapped * pOVERLAP)
我使用循环调用以下代码:
var tcpb = new NetTcpBinding();
TimeSpan timeOutAfter = new TimeSpan(0, 10,0);
tcpb.OpenTimeout = timeOutAfter;
tcpb.SendTimeout = timeOutAfter;
tcpb.CloseTimeout = timeOutAfter;
tcpb.Security.Mode = SecurityMode.None;
string address = "net.tcp://" + MYIP + ":" + PORTNUMBER + "/" + PORTTYPE + "/";
ChannelFactory<ServiceName> channelFactory = new ChannelFactory<ServiceName>(tcpb,address);
var client = channelFactory.CreateChannel();
((IClientChannel)client).Open();
//Function Call here
((IClientChannel)client).Close();
channelFactory.Close();
非常感谢任何想法和解决方案。
答案 0 :(得分:0)
我的猜测是你的服务无法应对80个并发呼叫。
查看WCF Throttling以配置您的服务应支持的最大并发呼叫数。 Code Project关于此问题有一个很好的主题。
TCP绑定的默认InstanceContextMode也是PerSession,WCF的默认行为是允许最多16个并发会话。如果不需要会话模式,则应将服务配置为使用InstanceContextMode.PerCall。这比PerSession更具可扩展性......