套接字连接中断:The socket connection was aborted
2012-07-11 10:27
706 查看
问题还原:我们的存储服务是基于WCF服务实现的,协议采用NetTcpBinding(约定,不可变更的),数据库中有一张表(图片信息是以二进制方式存储的),我们在插入一个小于64K的图片时,并没有产生任何错误。然而当我们添加一个90K的图片时,便产生了红色的异常信息。
The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was
'00:09:59.9669967'.
WCF编程开发过程时,使用NetTcpBinding绑定协议,作为通讯协议,可能会引发这样的异常,导致数据如法传输。套接字连接中断,可能是由于消息处理错误,或者远程宿主接受超时引起,或者是底层网络资源问题导致,本地套接字时间是'00:09:59.9669967'。MSDN上讨论的解决办法,更换其他的绑定协议确实可以解决问题,解决方案如下:
不过这种方案在某些情况下并不适用
问题关键:查看详细的异常的信息,我们发现一个值(65535)64K大小的限制 ,这个值一般是由于并没有对传输大小进行配置,采用了默认配置。仔细确认后,我们发现服务器端的maxBufferSize并未大小设置,导致了这个问题。
因为我们使用的通信协议是无法变更的!我们在不改变绑定协议的基础上的解决方案如下:
1.检查客户端及服务器的服务配置文件,在配置文件中需要调整的一些参数:
2.确保可序列化的对象的大小,同样在客户端或服务器端配置:
Client配置:
Server配置:
The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was
'00:09:59.9669967'.
WCF编程开发过程时,使用NetTcpBinding绑定协议,作为通讯协议,可能会引发这样的异常,导致数据如法传输。套接字连接中断,可能是由于消息处理错误,或者远程宿主接受超时引起,或者是底层网络资源问题导致,本地套接字时间是'00:09:59.9669967'。MSDN上讨论的解决办法,更换其他的绑定协议确实可以解决问题,解决方案如下:
WSHttpBinding binding = new WSHttpBinding(); binding.ReceiveTimeout = new TimeSpan(10, 10, 10);
不过这种方案在某些情况下并不适用
问题关键:查看详细的异常的信息,我们发现一个值(65535)64K大小的限制 ,这个值一般是由于并没有对传输大小进行配置,采用了默认配置。仔细确认后,我们发现服务器端的maxBufferSize并未大小设置,导致了这个问题。
因为我们使用的通信协议是无法变更的!我们在不改变绑定协议的基础上的解决方案如下:
1.检查客户端及服务器的服务配置文件,在配置文件中需要调整的一些参数:
<bindings> <netTcpBinding> <binding name="MyTcpBinding" closeTimeOut="10:00:00" openTimeOut="10:00:00" recieveTimeOut="10:00:00" sendTimeOut="10:00:00" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxRecieveMessageSize="2147483647"> <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/> <reliableSession inactivityTimeout="24.00:00:00" /> <security mode="None"/> </netTcpBinding> </bindings>
2.确保可序列化的对象的大小,同样在客户端或服务器端配置:
Client配置:
<endpointBehaviors> <behavior name="ClientBehavior"> <dataContractSerializer maxItemsInObjectGraph="2147483647"/> </behavior> </endpointBehaviors>
Server配置:
<serviceBehaviors> <behavior name="HostBehavior"> <dataContractSerializer maxItemsInObjectGraph="2147483647"/> </behavior> <serviceBehaviors>
相关文章推荐
- WCF分布式开发常见错误(10):套接字连接中断,The socket connection was aborted
- WCF分布式开发常见错误(10):套接字连接中断,The socket connection was aborted
- 连接数据库时的异常:TNS:listener does not currently know of SID given in connect descriptor The Connection descriptor used by the client was: localhost:1521:orc
- django an established connection was aborted by the software in you host machine
- HttpWebRequest:基础连接已关闭异常:The underlying connection was closed。
- 解决Windows用vnc连接Ubuntu时出现The connection was refused by the host computer问题
- An established connection was aborted by the software in your host machine
- java 连接 mssql2005 The user is not associated with a trusted SQL Server connection.
- System.ServiceModel.CommunicationException:The underlying connection was closed: The connection was closed unexpectedly
- oracle 11g JDBC连接数据库:IO异常The Network Adapter could not establish the connection 解决方法
- redis error It was not possible to connect to the redis server(s); to create a disconnected multiplexer, disable AbortOnConnectFail. SocketFailure on PING
- robot framework连接Oracle错误:ORA-12504: TNS:listener was not given the SERVICE_NAME in CONNECT_DATA
- 不能为虚拟电脑 麒麟 打开一个新任务. The VM session was aborted的解决办法
- The underlying connection was closed错误
- NodeJS连接MySQL时遇到的问题 Error: Connection lost: The server closed the connection.
- [Android_Bug]处理PhoneGap Application Error: "The connection to the server was unsuccessful.(file:///android_asset/www/index.html)"的错误
- Application Error - The connection to the server was unsuccessful.
- SecureCRT连接Ubuntu报The remote system refused the connection.解决方案
- [置顶] 数据库连接错误The Network Adapter could not establish the connection
- Qt QTcpSocket 对连接服务器中断的不同情况进行判定