The underlying connection was closed,让我很崩溃!!
2009-03-26 14:23
302 查看
以下摘自:
http://bloggingabout.net/blogs/marko/archive/2008/10/06/the-underlying-connection-was-closed-revisited.aspx
拱学习之用,同时也希望能解决这个问题.
So, the underlying connection was closed, again.
Those of us who have been consuming webservices from a .NET application, will probably have seen the error message "The Underlying connection was closed: An unexpected error occurred on a send." (or a receive).
Search for the error on google, and you'll get like 35k+ results. Most of which are blog postings or forum threads. Of course you'll get some MSDN articles. And other misc pages showing just the error message.
A real common solution to this problem is the following, well known, piece of code:
protected override System.Net.WebRequest GetWebRequest(Uri uri)
{
System.Net.HttpWebRequest webRequest =
(System.Net.HttpWebRequest) base.GetWebRequest(uri);
webRequest.KeepAlive = false;
return webRequest;
}
Other common solutions involve, for example, tweaking the IIS server, or updating the .NET Framework to have the latest patches.
So what's new?
Recently, we had the same problem in our project. Naturaly the first thing we did was check the known solutions. Most of them were already applied because of previous problems. A few solutions were new, but didn't do the trick.
Finally, we decided to use a little tool named tcpTrace. Hooking it up between our client app and the webservice allowed us to see all the http traffic going back and forth. The last incoming http data before the underlying connection got closed turned out to contain the following message from the webserver: "maximum request length exceeded".
Turns out, the default maximum request length of IIS is 2 megabytes. Our SOAP request was a bit larger. Adding the following line to the system.web section of the webservice's web.config fixed it all:
<httpRuntime maxRequestLength="10240"/>
http://bloggingabout.net/blogs/marko/archive/2008/10/06/the-underlying-connection-was-closed-revisited.aspx
拱学习之用,同时也希望能解决这个问题.
So, the underlying connection was closed, again.
Those of us who have been consuming webservices from a .NET application, will probably have seen the error message "The Underlying connection was closed: An unexpected error occurred on a send." (or a receive).
Search for the error on google, and you'll get like 35k+ results. Most of which are blog postings or forum threads. Of course you'll get some MSDN articles. And other misc pages showing just the error message.
A real common solution to this problem is the following, well known, piece of code:
protected override System.Net.WebRequest GetWebRequest(Uri uri)
{
System.Net.HttpWebRequest webRequest =
(System.Net.HttpWebRequest) base.GetWebRequest(uri);
webRequest.KeepAlive = false;
return webRequest;
}
Other common solutions involve, for example, tweaking the IIS server, or updating the .NET Framework to have the latest patches.
So what's new?
Recently, we had the same problem in our project. Naturaly the first thing we did was check the known solutions. Most of them were already applied because of previous problems. A few solutions were new, but didn't do the trick.
Finally, we decided to use a little tool named tcpTrace. Hooking it up between our client app and the webservice allowed us to see all the http traffic going back and forth. The last incoming http data before the underlying connection got closed turned out to contain the following message from the webserver: "maximum request length exceeded".
Turns out, the default maximum request length of IIS is 2 megabytes. Our SOAP request was a bit larger. Adding the following line to the system.web section of the webservice's web.config fixed it all:
<httpRuntime maxRequestLength="10240"/>
相关文章推荐
- The underlying connection was closed:Could not establish trust relationship for the SSL/TLS secure
- The underlying connection was closed错误
- [WebException: The underlying connection was closed: The message length limit was exceeded.]解决方法
- The underlying connection was closed: An unexpected error occurred on a send
- the underlying connection was closed:the server committed a protocol violation
- The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure
- [bug]The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
- System.ServiceModel.CommunicationException:The underlying connection was closed: The connection was closed unexpectedly
- The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure
- Bug record1: The underlying connection was closed: The connection was closed unexpectedly.Then
- 解决"The underlying connection was closed: A connection that was expected to be kept alive was closed"
- FtpWebRequest UploadFile返回"The underlying connection was closed: The server committed a protocol violation."解决方法
- EX:The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
- The underlying connection was closed错误
- EX:The underlying connection was closed: Could not
- HttpWebRequest:基础连接已关闭异常:The underlying connection was closed。
- Exception : The underlying connection was closed: A connection that was expected to be kept alive was closed by the server
- java.sql.SQLException: No operations allowed after connection closed.Connection was implicitly closed due to underlying exceptio
- An existing connection was forcibly closed by the remote host
- No operations allowed after connection closed.Connection was implicitly closed by the driver