【发布时间】:2014-02-17 01:51:12
【问题描述】:
我已经看到了以下问题及其无效的答案。
- No matter what I try: The I/O operation has been aborted because of either a thread exit or an application request
- The I/O operation has been aborted because of either a thread exit or an application request
- 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()
在 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();
非常感谢任何想法和解决方案。
【问题讨论】:
-
如果你需要别人的帮助,你应该发布代码......展示你如何测试服务。
-
@TMcKeown 我已经在我的问题中添加了我的调用代码。
-
您确定在通话后等待的时间足够长吗?如果您执行许多并发调用,那么我猜您可能会得到一些响应延迟。你不会太早关闭套接字吗?
-
我所有的超时时间都是 10 分钟。我在跟踪中没有任何超时。
-
好的,但我看到你在调用 .Close()... 什么时候调用?立即地?正如您在堆栈跟踪中看到的那样,在等待响应时发生了错误。
标签: c# multithreading wcf