469,621 Members | 1,685 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,621 developers. It's quick & easy.

Cannot access a disposed object named "System.Net.TlsStream".

I am getting the following error when sending a first http request:

Cannot access a disposed object named "System.Net.TlsStream".

After that everything sems to be fine untill the next long idle period. The
code is below. Any helpful ideas would be appriciated.
Encoding oEnc = System.Text.Encoding.GetEncoding(1252);
oNc = new NetworkCredential(cUserName, cPassWord);

oWebReq = (HttpWebRequest) WebRequest.Create(cUrl);
oWebReq.Timeout = 30000;
oWebReq.ContentType = "text/xml";
oWebReq.Method = "POST";
oWebReq.ContentLength = bBuffer.Length;

// -- request ---
oPostStream = oWebReq.GetRequestStream();
oPostStream.Write(bBuffer,0,bBuffer.Length);
oPostStream.Close();

// -- response ---
oWebRes = (HttpWebResponse) oWebReq.GetResponse();

oResStream = new StreamReader(oWebRes.GetResponseStream(),oEnc);
cRes = oResStream.ReadToEnd();
Nov 16 '05 #1
5 6446
SMike,

Is the url a secure url perhaps? The TlsStream I believe, is used to
handle SSL socket connections (for HTTPS). Based on the code here, I can't
see anything that would cause this problem.

Can you work up a small example, with a live URL perhaps?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"SMike" <mm******@hotmail.com> wrote in message
news:uV**************@TK2MSFTNGP11.phx.gbl...
I am getting the following error when sending a first http request:

Cannot access a disposed object named "System.Net.TlsStream".

After that everything sems to be fine untill the next long idle period.
The
code is below. Any helpful ideas would be appriciated.
Encoding oEnc = System.Text.Encoding.GetEncoding(1252);
oNc = new NetworkCredential(cUserName, cPassWord);

oWebReq = (HttpWebRequest) WebRequest.Create(cUrl);
oWebReq.Timeout = 30000;
oWebReq.ContentType = "text/xml";
oWebReq.Method = "POST";
oWebReq.ContentLength = bBuffer.Length;

// -- request ---
oPostStream = oWebReq.GetRequestStream();
oPostStream.Write(bBuffer,0,bBuffer.Length);
oPostStream.Close();

// -- response ---
oWebRes = (HttpWebResponse) oWebReq.GetResponse();

oResStream = new StreamReader(oWebRes.GetResponseStream(),oEnc);
cRes = oResStream.ReadToEnd();

Nov 16 '05 #2
Nicholas,

Thanks for a response. You are right - https is used. can't give you a
link - it's internal. I found such a problem is being discussed, but could
not find a solution.


"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:O5**************@TK2MSFTNGP15.phx.gbl...
SMike,

Is the url a secure url perhaps? The TlsStream I believe, is used to
handle SSL socket connections (for HTTPS). Based on the code here, I can't see anything that would cause this problem.

Can you work up a small example, with a live URL perhaps?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"SMike" <mm******@hotmail.com> wrote in message
news:uV**************@TK2MSFTNGP11.phx.gbl...
I am getting the following error when sending a first http request:

Cannot access a disposed object named "System.Net.TlsStream".

After that everything sems to be fine untill the next long idle period.
The
code is below. Any helpful ideas would be appriciated.
Encoding oEnc = System.Text.Encoding.GetEncoding(1252);
oNc = new NetworkCredential(cUserName, cPassWord);

oWebReq = (HttpWebRequest) WebRequest.Create(cUrl);
oWebReq.Timeout = 30000;
oWebReq.ContentType = "text/xml";
oWebReq.Method = "POST";
oWebReq.ContentLength = bBuffer.Length;

// -- request ---
oPostStream = oWebReq.GetRequestStream();
oPostStream.Write(bBuffer,0,bBuffer.Length);
oPostStream.Close();

// -- response ---
oWebRes = (HttpWebResponse) oWebReq.GetResponse();

oResStream = new StreamReader(oWebRes.GetResponseStream(),oEnc);
cRes = oResStream.ReadToEnd();


Nov 16 '05 #3
SMike wrote:
I am getting the following error when sending a first http request:

Cannot access a disposed object named "System.Net.TlsStream".

After that everything sems to be fine untill the next long idle period. The
code is below. Any helpful ideas would be appriciated.
Encoding oEnc = System.Text.Encoding.GetEncoding(1252);
oNc = new NetworkCredential(cUserName, cPassWord);

oWebReq = (HttpWebRequest) WebRequest.Create(cUrl);
oWebReq.Timeout = 30000;
oWebReq.ContentType = "text/xml";
oWebReq.Method = "POST";
oWebReq.ContentLength = bBuffer.Length;

// -- request ---
oPostStream = oWebReq.GetRequestStream();
oPostStream.Write(bBuffer,0,bBuffer.Length);
oPostStream.Close();

// -- response ---
oWebRes = (HttpWebResponse) oWebReq.GetResponse();

oResStream = new StreamReader(oWebRes.GetResponseStream(),oEnc);
cRes = oResStream.ReadToEnd();


Are you closing oResStream somewere? You must assure that
the stream is closed.

bye
Rob
Nov 16 '05 #4
Rod, I do that.

Could you tell if the following settings can cause such a behavior

ServicePointManager.MaxServicePoints = 15;
ServicePointManager.DefaultConnectionLimit = 15;
ServicePointManager.MaxServicePointIdleTime - how can this setting help?

Thanx in advance
Mike


"Robert Jordan" <ro*****@gmx.net> wrote in message
news:ci*************@news.t-online.com...
SMike wrote:
I am getting the following error when sending a first http request:

Cannot access a disposed object named "System.Net.TlsStream".

After that everything sems to be fine untill the next long idle period. The code is below. Any helpful ideas would be appriciated.
Encoding oEnc = System.Text.Encoding.GetEncoding(1252);
oNc = new NetworkCredential(cUserName, cPassWord);

oWebReq = (HttpWebRequest) WebRequest.Create(cUrl);
oWebReq.Timeout = 30000;
oWebReq.ContentType = "text/xml";
oWebReq.Method = "POST";
oWebReq.ContentLength = bBuffer.Length;

// -- request ---
oPostStream = oWebReq.GetRequestStream();
oPostStream.Write(bBuffer,0,bBuffer.Length);
oPostStream.Close();

// -- response ---
oWebRes = (HttpWebResponse) oWebReq.GetResponse();

oResStream = new StreamReader(oWebRes.GetResponseStream(),oEnc);
cRes = oResStream.ReadToEnd();


Are you closing oResStream somewere? You must assure that
the stream is closed.

bye
Rob

Nov 16 '05 #5
sorry for too many messages. I was getting errors while sending them.
"SMike" <mm******@hotmail.com> wrote in message
news:uV**************@TK2MSFTNGP11.phx.gbl...
I am getting the following error when sending a first http request:

Cannot access a disposed object named "System.Net.TlsStream".

After that everything sems to be fine untill the next long idle period. The code is below. Any helpful ideas would be appriciated.
Encoding oEnc = System.Text.Encoding.GetEncoding(1252);
oNc = new NetworkCredential(cUserName, cPassWord);

oWebReq = (HttpWebRequest) WebRequest.Create(cUrl);
oWebReq.Timeout = 30000;
oWebReq.ContentType = "text/xml";
oWebReq.Method = "POST";
oWebReq.ContentLength = bBuffer.Length;

// -- request ---
oPostStream = oWebReq.GetRequestStream();
oPostStream.Write(bBuffer,0,bBuffer.Length);
oPostStream.Close();

// -- response ---
oWebRes = (HttpWebResponse) oWebReq.GetResponse();

oResStream = new StreamReader(oWebRes.GetResponseStream(),oEnc);
cRes = oResStream.ReadToEnd();

Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Chris Botha | last post: by
4 posts views Thread by Chris Botha | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.