473,657 Members | 2,535 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HttpWebRequest intermittent trouble: ConnectionClose d, SecureChannelFa ilure, 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.WebE xception: The underlying connection was closed: Could
not establish secure channel for SSL/TLS. ---System.Net.WebE xception:
The request was aborted: The connection was closed unexpectedly.
============
System.ObjectDi sposedException : Cannot access a disposed object named
"System.Net.Tls Stream".
Object name: "System.Net.Tls Stream".
============
System.IO.IOExc eption: Unable to write data to the transport
connection. ---System.IO.IOExc eption: Unable to write data to the
transport connection. ---System.Net.Sock ets.SocketExcep tion: 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.Web Exception" 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(str ing url, string request)
{
UTF8Encoding enc = new UTF8Encoding();
byte [] data = enc.GetBytes(re quest);

HttpWebRequest req = (HttpWebRequest )WebRequest.Cre ate(url);
req.Method = "POST";
req.ContentLeng th = 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.ReadWriteTi meout = 99999;
req.ServicePoin t.MaxIdleTime = 99999;

Stream reqStream = req.GetRequestS tream();
reqStream.Write (data, 0, data.Length);
reqStream.Close ();
HttpWebResponse resp = (HttpWebRespons e)req.GetRespon se();
if (req.HaveRespon se)
{
if (resp.StatusCod e == HttpStatusCode. OK || resp.StatusCode ==
HttpStatusCode. Accepted)
{
StreamReader reader = new StreamReader(re sp.GetResponseS tream());
return reader.ReadToEn d();
}
else
{
throw new Exception("Requ est failed: " + resp.StatusDesc ription);
}
}
return null;
}
=============== =============== ==
System.Net.WebE xception: The underlying connection was closed: Could
not establish secure channel for SSL/TLS. ---System.Net.WebE xception:
The request was aborted: The connection was closed unexpectedly.
at System.Net.TlsS tream.EndRead(I AsyncResult asyncResult)
at System.Net.Conn ection.ReadCall back(IAsyncResu lt asyncResult)
--- End of inner exception stack trace ---
at System.Net.Http WebRequest.Chec kFinalStatus()
at System.Net.Http WebRequest.EndG etRequestStream (IAsyncResult
asyncResult)
at System.Net.Http WebRequest.GetR equestStream()
at HttpRequestPost XML_Console.Cla ss1.SendRequest (String url, String
request) in c:\projects\htt prequestpostxml _console\class1 .cs:line 176
at HttpRequestPost XML_Console.Cla ss1.Test1() in
c:\projects\htt prequestpostxml _console\class1 .cs:line 53

WebException.St atus = SecureChannelFa ilure

System.Net.WebE xception: The request was aborted: The connection was
closed unexpectedly.
at System.Net.TlsS tream.EndRead(I AsyncResult asyncResult)
at System.Net.Conn ection.ReadCall back(IAsyncResu lt asyncResult)

WebException.St atus = ConnectionClose d

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

System.ObjectDi sposedException : Cannot access a disposed object named
"System.Net.Tls Stream".
Object name: "System.Net.Tls Stream".
at System.Net.TlsS tream.InnerWrit e(Boolean async, Byte[] buffer,
Int32 offset, Int32 size, AsyncCallback asyncCallback, Object
asyncState)
at System.Net.TlsS tream.BeginWrit e(Byte[] buffer, Int32 offset,
Int32 size, AsyncCallback asyncCallback, Object asyncState)
at System.Net.Conn ection.BeginWri te(Byte[] buffer, Int32 offset,
Int32 size, AsyncCallback callback, Object state)
at System.Net.Conn ectStream.Begin Write(Byte[] buffer, Int32 offset,
Int32 size, AsyncCallback callback, Object state)
at System.Net.Conn ectStream.Write (Byte[] buffer, Int32 offset, Int32
size)
at HttpRequestPost XML_Console.Cla ss1.SendRequest (String URL, String
request) in c:\projects\htt prequestpostxml _console\class1 .cs:line 135
at HttpRequestPost XML_Console.Cla ss1.Test1() in
c:\projects\htt prequestpostxml _console\class1 .cs:line 53

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

System.IO.IOExc eption: Unable to write data to the transport
connection. ---System.IO.IOExc eption: Unable to write data to the
transport connection. ---System.Net.Sock ets.SocketExcep tion: An
established connection was aborted by the software in your host machine
at System.Net.Sock ets.Socket.Begi nSend(Byte[] buffer, Int32 offset,
Int32 size, SocketFlags socketFlags, AsyncCallback callback, Object
state)
at System.Net.Sock ets.NetworkStre am.BeginWrite(B yte[] buffer, Int32
offset, Int32 size, AsyncCallback callback, Object state)
--- End of inner exception stack trace ---
at System.Net.Sock ets.NetworkStre am.BeginWrite(B yte[] buffer, Int32
offset, Int32 size, AsyncCallback callback, Object state)
at System.Net.TlsS tream.InnerWrit e(Boolean async, Byte[] buffer,
Int32 offset, Int32 size, AsyncCallback asyncCallback, Object
asyncState)
--- End of inner exception stack trace ---
at System.Net.TlsS tream.InnerWrit e(Boolean async, Byte[] buffer,
Int32 offset, Int32 size, AsyncCallback asyncCallback, Object
asyncState)
at System.Net.TlsS tream.BeginWrit e(Byte[] buffer, Int32 offset,
Int32 size, AsyncCallback asyncCallback, Object asyncState)
at System.Net.Conn ection.BeginWri te(Byte[] buffer, Int32 offset,
Int32 size, AsyncCallback callback, Object state)
at System.Net.Conn ectStream.Begin Write(Byte[] buffer, Int32 offset,
Int32 size, AsyncCallback callback, Object state)
at System.Net.Conn ectStream.Write (Byte[] buffer, Int32 offset, Int32
size)
at HttpRequestPost XML_Console.Cla ss1.SendRequest (String URL, String
request) in c:\projects\htt prequestpostxml _console\class1 .cs:line 151
at HttpRequestPost XML_Console.Cla ss1.Test1() in
c:\projects\htt prequestpostxml _console\class1 .cs:line 53

WebException: The request was aborted: The connection was closed
unexpectedly.
at System.Net.Conn ectStream.Begin Write(Byte[] buffer, Int32 offset,
Int32 size, AsyncCallback callback, Object state)
at System.Net.Conn ectStream.Write (Byte[] buffer, Int32 offset, Int32
size)
at HttpRequestPost XML_Console.Cla ss1.SendRequest (String URL, String
request) in c:\projects\htt prequestpostxml _console\class1 .cs:line 157
at HttpRequestPost XML_Console.Cla ss1.Test1() in
c:\projects\htt prequestpostxml _console\class1 .cs:line 53

WebException.St atus = ConnectionClose d

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

Thanks,

Josh Blair
Evergreen, CO

Dec 7 '06 #1
0 2568

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

Similar topics

16
12634
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 MSHTML objects to really load the HTML and request all of the images on site? string lcUrl = http://www.cnn.com; // *** Establish the request
8
11054
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 my code it takes about 10-12 secs to complete, but doing same request in my browser takes less than 1 sec. Can anyone explain this delay from within my code ??
0
1293
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 appreciated. I've built a C# web site that uses the WebRequest object to send a request to another server via https and receive an XML response. Periodically, the WebRequest object throws a WebException with the SecureChannelFailure status....
7
7617
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
2601
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 display a waiting message while it requests XML data from a third party server. Some requests can take around 30 seconds. Usually the first time I do the request it always works. If I try again without closing the web browser it will fail sometimes....
6
1962
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 able to help me. Here is the code that i am using: Dim url As String = "MyIP" Dim httpRequest As HttpWebRequest = CType(WebRequest.Create(url),
3
4337
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 response from the server is not making it back because the return port back to the client software being blocked by the firewall. This seems to be an intermittent problem because some of the ports are open through the firewall and some are not....
1
4701
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 don't know why. The application screen scrapes a web page. If I paste the URL in my browser's address bar and the expected page comes up just fine. When I went through the hassle of getting the real response from within the exception object,...
0
6624
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 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...
0
8413
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8324
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8842
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8513
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8617
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2742
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.