Jeff Sanders Technical Blog

I am a Microsoft employee that has worked on all aspects of the Web Stack for a long time. I hope these blogs are useful to you! Use this information at your own risk.


<< Go Back

You Receive One Or More Error Messages When You Try To Make An Http Request In An Application That Is Built On The Net Framework 2 0

- 07 Jan 2009

Please send me a message or leave a comment to let me know if this Post helped you! 

When you try to make an HTTP request in an application that is built on the .NET Framework, you may receive one or more of the following error messages or Exceptions.

One of the first things you should do is see what the framework is doing.  Get a System.Net trace: http://blogs.msdn.com/jpsanders/archive/2009/03/24/my-favorite-system-net-trace-configuration-file-dumps-process-id-and-date-time-information.aspx

Then you can get a description of the errors here (note this is an enumeration which is the status member of the WebException):
http://msdn.microsoft.com/en-us/library/system.net.webexceptionstatus(VS.80).aspx

Many of these errors are the same in the 1.1 .NET framework:
http://support.microsoft.com/kb/915599

Some of these errors can be trapped and immediately retried such as:<div class=indent>System.Net.WebExceptionStatus.ConnectFailure:

System.Net.WebExceptionStatus.KeepAliveFailure:
System.Net.WebExceptionStatus.RequestCanceled:
System.Net.WebExceptionStatus.ConnectionClosed:
System.Net.WebExceptionStatus.SendFailure:
System.Net.WebExceptionStatus.<span id=#h1 class=KeywordHighlight>PipelineFailure</span>:
System.Net.WebExceptionStatus.UnknownError:</div> <div class=indent> </div> <div class=indent>Errors: </div> <div class=indent> </div> <div class=indent>The underlying connection was closed: The remote name could not be resolved</div> <div class=indent> </div> <div class=indent>This is a DNS error.  For some reason the server name cannot be resolved.  Do you have permissions to the HOST file?  Is this a service such as ASP.NET?  See this article for help: The underlying connection was closed: The remote name could not be resolved.  Also look at this KB: http://support.microsoft.com/kb/330221</div> <div class=indent> </div> <div class=indent> </div> <div class=indent>The underlying connection was closed: Unable to connect to the remote server</div> <div class=indent> </div> <div class=indent>This is a connection issue.  The DNS resolved the server name but something is preventing the client from connecting to the server.  Lookup the error in this article http://support.microsoft.com/kb/915599.  </div> <div class=indent> </div> <div class=indent> </div> <div class=indent>The underlying connection was closed: An unexpected error occurred on a receive</div> <div class=indent> </div> <div class=indent>This problem occurs when the server or another network device unexpectedly closes an existing Transmission Control Protocol (TCP) connection.  Lookup the error in this article http://support.microsoft.com/kb/915599. </div> <div class=indent> </div> <div class=indent> </div> <div class=indent>The underlying connection was closed: An unexpected error occurred on a send</div> <div class=indent> </div> <div class=indent>This problem occurs when the client computer cannot send an HTTP request. The client computer cannot send the HTTP request because the connection has been closed or is unavailable.  Lookup the error in this article http://support.microsoft.com/kb/915599.  Antivirus software can interfere with the send as well.  If the stack from the exception includes something similar to this:</div> <div class=indent>System.IO.IOException: Authentication failed because the remote party has closed the transport stream.</div> <div class=indent>It is possible that the server is an older server does not understand TLS and so you need to change this as specified in the 915599 kb to something like this:</div> <div class=indent>

ServicePointManager.SecurityProtocol= SecurityProtocolType.Ssl3;
<font color=#000000 face=Arial>Before you make any HTTPS calls in your application.</font>

</div> <div class=indent>

The underlying connection was closed: A <span id=#h6 class=KeywordHighlight>pipeline failure</span> occurred</div> <div class=indent> </div> <div class=indent>Pipelined requests are requests sent out on the same socket without waiting for a reply (http://search.live.com/search?q=http+pipelined+request).  All HTTP 1.1 servers are required to support pipelining.  In general if you see this error it is probable related to a network related failure.  You could turn off pipelining and try to see what the underlying issue is but pipelining itself is rarely the cause of this error message.  You should retry the request if you get this error but if you get this exception multiple times, you should troubleshoot the root cause.</div> <div class=indent> </div> <div class=indent>The underlying connection was closed: The request was canceled</div> <div class=indent> <div class=indent>The underlying connection was closed: The connection was closed unexpectedly</div> <div class=indent> </div> </div> <div class=indent>This occurs with the server cancels the request with a TCP RST (reset).  The server may do this because of the thread Execution Timeout Setting being too low and it is tearing down the thread that is processing the request (Thread Abort Exceptions may be logged):  http://msdn.microsoft.com/en-us/library/e1f13641.aspx</div> <div class=indent>Also check and ensure the Keep-Alive timeouts on the server, load balancer and client (.NET) are set so that the client is set to less than the load balancer, which in turn is set less than the server.  See this article as well: </div> <div class=indent> </div> <div class=indent>The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel</div> <div class=indent> </div> <div class=indent>For a service application the whole certificate chain needs to be in the LOCAL_MACHINE store.  This means the Root in the Trusted Root Certificate and all the Intermediate Certificates in the Trusted Intermedeate store.  For applications that run in the context of the logged on user, If Internet Explorer does not have any Certificate problems, then the .NET application should work fine.  Often people will find that Internet Explorer is fine and only the ASP.NET or Service application fails.  This is because the root and intermediate certificates are installed correctly in the user store but not the local machine store.</div> <div class=indent>You can dump out what the failure is by using this delegate: http://msdn.microsoft.com/en-us/library/system.net.security.remotecertificatevalidationcallback.aspx.  Finally you could use process monitor and verify that there are no access denied errors when trying to access the certificate store which would prevent reading the certificates.</div> <div class=indent> </div> <div class=indent>The request was aborted: Could not create SSL/TLS secure channel</div> <div class=indent> </div> <div class=indent>Lookup the error in this article http://support.microsoft.com/kb/915599  Resolution J.  It also may be that you are not supplying a client certificate.  Most likely this is an issue with TLS or SSL3 being used and the server not understanding it.</div> <div class=indent> </div> <div class=indent>Error: The server committed a protocol violation</div> <div class=indent> </div> <div class=indent>The Exception will tell what the HTTP protocol violation is: </div> <div class=indent>“<span id=#h3 class=KeywordHighlight>The server committed a protocol violation</span>. Section=ResponseHeader Detail=Header
name is invalid” </div> <div class=indent>Fix the server to conform to the HTTP RFCs to avoid this error.  .NET is a stickler that the HTTP Protocol be followed.</div> <div class=indent> </div> <div class=indent>The underlying connection was closed: A connection that was expected to be kept alive was closed by the server</div> <div class=indent> </div> <div class=indent>Specifically a Keep-Alive connection was torn down before it should have been.  This is often caused because the MaxIdleTimeout setting in the client is greater than that of the server or intermediate network device (load balancer or proxy). </div> <div class=indent>http://support.microsoft.com/?id=941633 and http://support.microsoft.com/kb/915599 Resolution E</div> <div class=indent> </div> <div class=indent>The operation has timed out</div> <div class=indent> </div> <div class=indent>This could be caused by a stale DNS entry for a proxy or if a request is not received before the socket times out.</div> <div class=indent>An example of this Exception is when for example a server returns information but does not correctly set the content-length header.  The call will wait for the rest of the data (which will never come) until it throws this message.  It could be that the server takes a long time to respond (which is a different issue) and you could increase System.<span id=#h64 class=KeywordHighlight>Net</span>.ServicePointManager.DefaultConnectionLimit.  This could also be because you are issuing a lot of request and have not increased the DefaultMaxConnections for your application and the timeout happens waiting for a connection thread to process your request.  MaxConnections can be set in the application.config file or in code.</div> <div class=indent> </div> <div class=indent>The proxy name could not be resolved</div> <div class=indent> </div> <div class=indent>This is a DNS issue.  Find out what proxy it is looking for (from the System.Net trace) and find why this does not resolve in your network.</div> <div class=indent> </div> <div class=indent>The request was aborted: The request cache-only policy does not allow a network request and the response is not found in cache</div> <div class=indent>The request was aborted: The request could not be satisfied using a cache-only policy </div> <div class=indent> </div> <div class=indent> <div class=indent>The request was not permitted by the cache policy. In general, this occurs when a request is not cacheable and the effective policy prohibits sending the request to the server. You might receive this status if a request method implies the presence of a request body, a request method requires direct interaction with the server, or a request contains a conditional header. </div> </div> <div class=indent>You can control if the request should use only the cache: http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.defaultcachepolicy.aspx</div> <div class=indent>If you do this and the file in not cached, then you will get this error.</div> <div class=indent>Also see: http://msdn.microsoft.com/en-us/library/system.net.cache.httprequestcachepolicy(VS.80).aspx </div> <div class=indent> </div> <div class=indent> </div>

<< Go Back