Groups | Blog | Home
all groups > asp.net webservices > july 2004 >

asp.net webservices : Cannot access a disposed object named System.Net.TlsStream



patricioim NO[at]SPAM mixmail.com
7/13/2004 10:33:35 AM
Hello everybody

i have the following code to access an application via https:

---------------------------------------------
System.Net.ServicePointManager.CertificatePolicy = new
TrustAllCertificatePolicy();

httpWebRequest = (HttpWebRequest)WebRequest.Create(url);

X509Certificate cer =
X509Certificate.CreateFromCertFile(@"c:\CertificadoCliente.cer");

httpWebRequest.ClientCertificates.Add(cer);
httpWebRequest.Method = "POST";
httpWebRequest.ContentLength = stringPost.Length;

streamWriter = new StreamWriter(httpWebRequest.GetRequestStream());

streamWriter.Write(stringPost);
streamWriter.Close();

HttpWebResponse httpWebResponse =
(HttpWebResponse)httpWebRequest.GetResponse();
StreamReader streamReader = new
StreamReader(httpWebResponse.GetResponseStream());
respuesta = streamReader.ReadToEnd();
streamReader.Close();
---------------------------------------------

Although the connection is created (i think the certificates are
correctly installed), i got an exception when i try to close the
streamWriter:

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

As you can see i have created the TrustAllCertificatePolicy class, but
i still get that exception. Could anyone help me?

Tomas Restrepo (MVP)
7/13/2004 9:15:27 PM
Mackuack,

[quoted text, click to view]

You're closing the StreamWriter, which closes the underlying request stream.
You never get to actually listen for the response! Don't close the writer
(just flush it) until you're done with the request and have received a
response.

--
Tomas Restrepo
tomasr@mvps.org

patricioim NO[at]SPAM mixmail.com
7/15/2004 2:52:57 AM
[quoted text, click to view]

Really?

I have found the solution by myself, the problem was that i have the
client certificate installed only for the machine account. I have also
installed it for the current user and now all it´s working fine
without changing anything in the code.

Thanks a lot for your help.

AddThis Social Bookmark Button