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

S

SMike

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();
 
N

Nicholas Paldino [.NET/C# MVP]

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?
 
S

SMike

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 said:
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]
- (e-mail address removed)

SMike said:
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();
 
R

Robert Jordan

SMike said:
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
 
S

SMike

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top