由于WCF中的线程退出或应用程序请求,I / O操作已中止

问题描述 投票:3回答:1

我已经看到了以下问题和他们的非工作答案。

  1. No matter what I try: The I/O operation has been aborted because of either a thread exit or an application request
  2. The I/O operation has been aborted because of either a thread exit or an application request
  3. The I/O operation has been aborted because of either a thread exit or an application request

我有一个控制台应用程序,我正在压力测试我的WCF服务。当我对该服务进行80多个同时调用时,有时它可以正常工作,有时一些调用会因以下异常而失败。

异常类型:System.Net.Sockets.SocketException,System,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089

消息:由于线程退出或应用程序请求,I / O操作已中止

堆栈跟踪:

在System.ServiceModel.Channels.SocketConnection.HandleReceiveAsyncCompleted()

at System.ServiceModel.Channels.SocketConnection.OnReceiveAsync(Object sender,SocketAsyncEventArgs eventArgs)

在System.ServiceModel.Channels.SocketConnection.OnReceiveAsyncCompleted(Object sender,SocketAsyncEventArgs e)

在System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(SocketAsyncEventArgs e)

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

非常感谢任何想法和解决方案。

c# multithreading wcf
1个回答
0
投票

我的猜测是你的服务无法应付80个并发呼叫。

查看WCF Throttling以配置您的服务应支持的最大并发呼叫数。关于这个问题,Code Project有一个很好的主题。

此外,TCP绑定的默认InstanceContextMode是PerSession,WCF的默认行为是允许最多16个并发会话。如果不需要会话模式,则应将服务配置为使用InstanceContextMode.PerCall。这比PerSession更具可扩展性......

© www.soinside.com 2019 - 2024. All rights reserved.