473,320 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

HttpWebRequest intermittent trouble: ConnectionClosed, SecureChannelFailure, and others issues

I tried to post this to microsoft.public.dotnet.languages.csharp a week
ago with no results. Please excuse the "cross-post".

I am trying to post XML documents to a third party using the
HttpWebRequest. This URL uses HTTPS (SSL) but I don't have a client
certificate to deal with. Apparently they are using WebMethods as the
platform that receives these postings. I don't have any experience
with that technology.

The sample below is the from test app that I put together to post the
XML (cXML Order Requests) documents. These documents, at least my
simple samples aren't very large in size; maybe 4-8 KB in at the most.
The sample SendRequest method works 60-80% of the time in my testing.
The other 20-40% of the time I get a number of Exceptions, mostly
WebExceptions. See below:

============
System.Net.WebException: The underlying connection was closed: Could
not establish secure channel for SSL/TLS. ---System.Net.WebException:
The request was aborted: The connection was closed unexpectedly.
============
System.ObjectDisposedException: Cannot access a disposed object named
"System.Net.TlsStream".
Object name: "System.Net.TlsStream".
============
System.IO.IOException: Unable to write data to the transport
connection. ---System.IO.IOException: Unable to write data to the
transport connection. ---System.Net.Sockets.SocketException: An
established connection was aborted by the software in your host machine
|
L--(only got this one once so far...)
============
WebException: The request was aborted: The connection was closed
unexpectedly. (inner exception)
============
More exception details below the code sample.

Also, I found a KB article that looked like it might have been the
explanation but I installed a hotfix that updated the System.dll to the
version: 1.1.4322.2038 and I am still getting the same behavior.
=========
FIX: You may receive a "System.Net.WebException" error message when you
upload a large file over a SSL connection in the .NET Framework 1.1
Article ID: 884537
http://support.microsoft.com/kb/884537
=========

I tried setting a few timeout properties and the KeepAlive property of
the HttpWebRequest object with no real noticeable improvement. Any
ideas would be greatly appreciated.

public static string SendRequest(string url, string request)
{
UTF8Encoding enc = new UTF8Encoding();
byte [] data = enc.GetBytes(request);

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "POST";
req.ContentLength = data.Length;
req.ContentType = "text/xml";
req.KeepAlive = true;
req.UserAgent = null;

// tried setting these different timeouts with no real
improvement
req.Timeout = 99999;
req.ReadWriteTimeout = 99999;
req.ServicePoint.MaxIdleTime = 99999;

Stream reqStream = req.GetRequestStream();
reqStream.Write(data, 0, data.Length);
reqStream.Close();
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
if (req.HaveResponse)
{
if (resp.StatusCode == HttpStatusCode.OK ||
resp.StatusCode ==
HttpStatusCode.Accepted)
{
StreamReader reader = new
StreamReader(resp.GetResponseStream());
return reader.ReadToEnd();
}
else
{
throw new Exception("Request failed: " +
resp.StatusDescription);
}
}
return null;

}

================================
System.Net.WebException: The underlying connection was closed: Could
not establish secure channel for SSL/TLS. ---System.Net.WebException:
The request was aborted: The connection was closed unexpectedly.
at System.Net.TlsStream.EndRead(IAsyncResult asyncResult)
at System.Net.Connection.ReadCallback(IAsyncResult asyncResult)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.CheckFinalStatus()
at System.Net.HttpWebRequest.EndGetRequestStream(IAsy ncResult
asyncResult)
at System.Net.HttpWebRequest.GetRequestStream()
at HttpRequestPostXML_Console.Class1.SendRequest(Stri ng url, String
request) in c:\projects\httprequestpostxml_console\class1.cs:l ine 176
at HttpRequestPostXML_Console.Class1.Test1() in
c:\projects\httprequestpostxml_console\class1.cs:l ine 53

WebException.Status = SecureChannelFailure

System.Net.WebException: The request was aborted: The connection was
closed unexpectedly.
at System.Net.TlsStream.EndRead(IAsyncResult asyncResult)
at System.Net.Connection.ReadCallback(IAsyncResult asyncResult)

WebException.Status = ConnectionClosed

================================

System.ObjectDisposedException: Cannot access a disposed object named
"System.Net.TlsStream".
Object name: "System.Net.TlsStream".
at System.Net.TlsStream.InnerWrite(Boolean async, Byte[] buffer,
Int32 offset, Int32 size, AsyncCallback asyncCallback, Object
asyncState)
at System.Net.TlsStream.BeginWrite(Byte[] buffer, Int32 offset,
Int32 size, AsyncCallback asyncCallback, Object asyncState)
at System.Net.Connection.BeginWrite(Byte[] buffer, Int32 offset,
Int32 size, AsyncCallback callback, Object state)
at System.Net.ConnectStream.BeginWrite(Byte[] buffer, Int32 offset,
Int32 size, AsyncCallback callback, Object state)
at System.Net.ConnectStream.Write(Byte[] buffer, Int32 offset, Int32
size)
at HttpRequestPostXML_Console.Class1.SendRequest(Stri ng URL, String
request) in c:\projects\httprequestpostxml_console\class1.cs:l ine 135
at HttpRequestPostXML_Console.Class1.Test1() in
c:\projects\httprequestpostxml_console\class1.cs:l ine 53

===============================

System.IO.IOException: Unable to write data to the transport
connection. ---System.IO.IOException: Unable to write data to the
transport connection. ---System.Net.Sockets.SocketException: An
established connection was aborted by the software in your host machine
at System.Net.Sockets.Socket.BeginSend(Byte[] buffer, Int32 offset,
Int32 size, SocketFlags socketFlags, AsyncCallback callback, Object
state)
at System.Net.Sockets.NetworkStream.BeginWrite(Byte[] buffer, Int32
offset, Int32 size, AsyncCallback callback, Object state)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.BeginWrite(Byte[] buffer, Int32
offset, Int32 size, AsyncCallback callback, Object state)
at System.Net.TlsStream.InnerWrite(Boolean async, Byte[] buffer,
Int32 offset, Int32 size, AsyncCallback asyncCallback, Object
asyncState)
--- End of inner exception stack trace ---
at System.Net.TlsStream.InnerWrite(Boolean async, Byte[] buffer,
Int32 offset, Int32 size, AsyncCallback asyncCallback, Object
asyncState)
at System.Net.TlsStream.BeginWrite(Byte[] buffer, Int32 offset,
Int32 size, AsyncCallback asyncCallback, Object asyncState)
at System.Net.Connection.BeginWrite(Byte[] buffer, Int32 offset,
Int32 size, AsyncCallback callback, Object state)
at System.Net.ConnectStream.BeginWrite(Byte[] buffer, Int32 offset,
Int32 size, AsyncCallback callback, Object state)
at System.Net.ConnectStream.Write(Byte[] buffer, Int32 offset, Int32
size)
at HttpRequestPostXML_Console.Class1.SendRequest(Stri ng URL, String
request) in c:\projects\httprequestpostxml_console\class1.cs:l ine 151
at HttpRequestPostXML_Console.Class1.Test1() in
c:\projects\httprequestpostxml_console\class1.cs:l ine 53

WebException: The request was aborted: The connection was closed
unexpectedly.
at System.Net.ConnectStream.BeginWrite(Byte[] buffer, Int32 offset,
Int32 size, AsyncCallback callback, Object state)
at System.Net.ConnectStream.Write(Byte[] buffer, Int32 offset, Int32
size)
at HttpRequestPostXML_Console.Class1.SendRequest(Stri ng URL, String
request) in c:\projects\httprequestpostxml_console\class1.cs:l ine 157
at HttpRequestPostXML_Console.Class1.Test1() in
c:\projects\httprequestpostxml_console\class1.cs:l ine 53

WebException.Status = ConnectionClosed

================================

Thanks,

Josh Blair
Evergreen, CO

Dec 11 '06 #1
0 6587

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: thomas peter | last post by:
I am building a precache engine... one that request over 100 pages on an remote server to cache them remotely... can i use the HttpWebRequest and WebResponse classes for this? or must i use the...
8
by: Soeren S. Joergensen | last post by:
Hi, From a win-service I do a HttpWebRequest to a secure url with some parameters to get some simple data from a remote system used later on in a worker thread. When making the request from...
0
by: Joey Guerra | last post by:
Hi. I've been researching how to resolve this issue, but haven't found a solution. I saw a post referring to the SecureChannelFailure WebException status, but no resolution. Any help/direction is...
7
by: gorkos | last post by:
Hi, I am two days trying to solve a problem with some pages, which i get through HTTPWebRequest. Error is that some pages need Script to be enabled. But how to do this in HTTPWebRequest class?
1
by: sfoxover | last post by:
Hi, Could someone please give me some suggestions on how to make this class robust. I need to be able to handle around 20 similtanious requests to this class which causes a web browser to...
6
by: Oliver | last post by:
I have a very wired problem requesting one specific url from within my application. I have struggeled with this for 5 hours now, and searched google withour any luck, so i hope that someone are...
3
by: Bruce Wolfe | last post by:
We are having a problem with firewalls. We can't pinpoint the exact problem but the working theory at this point is the request from the client software is reaching the server through port 80. The...
1
by: mfreeman | last post by:
I have a VB.NET 2005 Windows application that worked fine when I ran it a month ago, and now it is throwing an exception ("The remote server returned an error: (500) Internal Server Error.") and I...
0
by: joshblair | last post by:
Hello, I am trying to post XML documents to a third party using the HttpWebRequest. This URL uses HTTPS (SSL) but I don't have a client certificate to deal with. Apparently they are using...
2
by: Ken Fine | last post by:
I have a question about ASP.NET output caching. I want to use screen scraping as a temporary hack to pull in some complex Classic ASP-rendered content into some ASP.NET pages: protected String...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.