473,404 Members | 2,114 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,404 software developers and data experts.

HttpWebRequest intermittent trouble: ConnectionClosed, SecureChannelFailure, and others issues

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 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 7 '06 #1
0 2536

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:
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.