The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure

Discussion in 'ASP .Net' started by Joel Barsotti, Apr 19, 2007.

  1. I'm working on shipping rate calculator going back and forth via XML. The
    thing I'm confused about is that the code works, but after a few hours and I
    don't know how many requests, I start getting the error "The underlying
    connection was closed: Could not establish trust relationship for the
    SSL/TLS secure channel." I can't imagine UPS's certificate is bad.

    Here's my code, let me know if you see any glaring issues.

    HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(upsRateUri);
    myReq.Headers.Clear();
    myReq.Method = "POST";
    myReq.ContentType = "application/x-www-form-urlencoded";
    myReq.ContentLength = xmlString.Length;
    StreamWriter sendingData = new StreamWriter(myReq.GetRequestStream());
    sendingData.Write(xmlString);
    sendingData.Close();
    WebResponse myResponse = myReq.GetResponse();
    Joel Barsotti, Apr 19, 2007
    #1
    1. Advertising

  2. My guess would be that you do not close Streams/Requests properly and at
    some time system runs out of them.
    Be very careful with lines like that
    StreamWriter sendingData = new StreamWriter(myReq.GetRequestStream());

    That is big problem with .NET (unfortunately). No ownership. Who is
    responsible for closing the Stream returned by myReq.GetRequestStream().

    Who told you that StreamWrite will close the underlying Stream? Actually my
    feeling from documentation it will not. All it will do just Flush own
    buffers and resets it's state.

    Again, i am not sure that this is your problem but usually if something
    works for couple hours and then stops that means you run out of some kind of
    system resources.


    George



    "Joel Barsotti" <> wrote in message
    news:...
    > I'm working on shipping rate calculator going back and forth via XML. The
    > thing I'm confused about is that the code works, but after a few hours and
    > I don't know how many requests, I start getting the error "The underlying
    > connection was closed: Could not establish trust relationship for the
    > SSL/TLS secure channel." I can't imagine UPS's certificate is bad.
    >
    > Here's my code, let me know if you see any glaring issues.
    >
    > HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(upsRateUri);
    > myReq.Headers.Clear();
    > myReq.Method = "POST";
    > myReq.ContentType = "application/x-www-form-urlencoded";
    > myReq.ContentLength = xmlString.Length;
    > StreamWriter sendingData = new StreamWriter(myReq.GetRequestStream());
    > sendingData.Write(xmlString);
    > sendingData.Close();
    > WebResponse myResponse = myReq.GetResponse();
    George Ter-Saakov, Apr 19, 2007
    #2
    1. Advertising

  3. Yeah I was starting to suspect that may be the case.

    "George Ter-Saakov" <> wrote in message
    news:...
    > My guess would be that you do not close Streams/Requests properly and at
    > some time system runs out of them.
    > Be very careful with lines like that
    > StreamWriter sendingData = new StreamWriter(myReq.GetRequestStream());
    >
    > That is big problem with .NET (unfortunately). No ownership. Who is
    > responsible for closing the Stream returned by myReq.GetRequestStream().
    >
    > Who told you that StreamWrite will close the underlying Stream? Actually
    > my feeling from documentation it will not. All it will do just Flush own
    > buffers and resets it's state.
    >
    > Again, i am not sure that this is your problem but usually if something
    > works for couple hours and then stops that means you run out of some kind
    > of system resources.
    >
    >
    > George
    >
    >
    >
    > "Joel Barsotti" <> wrote in message
    > news:...
    >> I'm working on shipping rate calculator going back and forth via XML. The
    >> thing I'm confused about is that the code works, but after a few hours
    >> and I don't know how many requests, I start getting the error "The
    >> underlying connection was closed: Could not establish trust relationship
    >> for the SSL/TLS secure channel." I can't imagine UPS's certificate is
    >> bad.
    >>
    >> Here's my code, let me know if you see any glaring issues.
    >>
    >> HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(upsRateUri);
    >> myReq.Headers.Clear();
    >> myReq.Method = "POST";
    >> myReq.ContentType = "application/x-www-form-urlencoded";
    >> myReq.ContentLength = xmlString.Length;
    >> StreamWriter sendingData = new StreamWriter(myReq.GetRequestStream());
    >> sendingData.Write(xmlString);
    >> sendingData.Close();
    >> WebResponse myResponse = myReq.GetResponse();

    >
    >
    Joel Barsotti, Apr 19, 2007
    #3
  4. Joel Barsotti

    carion1 Guest

    HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(upsRateUri);
    myReq.Headers.Clear();
    myReq.Method = "POST";
    myReq.ContentType = "application/x-www-form-urlencoded";
    myReq.ContentLength = xmlString.Length;

    using(StreamWriter sendingData = new
    StreamWriter(myReq.GetRequestStream()))
    {
    sendingData.Write(xmlString);
    sendingData.Flush();
    }

    WebResponse myResponse = myReq.GetResponse();

    On Apr 19, 11:07 am, "Joel Barsotti" <> wrote:
    > I'm working on shipping rate calculator going back and forth via XML. The
    > thing I'm confused about is that the code works, but after a few hours and I
    > don't know how many requests, I start getting the error "The underlying
    > connection was closed: Could not establish trust relationship for the
    > SSL/TLS secure channel." I can't imagine UPS's certificate is bad.
    >
    > Here's my code, let me know if you see any glaring issues.
    >
    > HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(upsRateUri);
    > myReq.Headers.Clear();
    > myReq.Method = "POST";
    > myReq.ContentType = "application/x-www-form-urlencoded";
    > myReq.ContentLength = xmlString.Length;
    > StreamWriter sendingData = new StreamWriter(myReq.GetRequestStream());
    > sendingData.Write(xmlString);
    > sendingData.Close();
    > WebResponse myResponse = myReq.GetResponse();
    carion1, Apr 19, 2007
    #4
  5. nope

    HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(upsRateUri);
    myReq.Headers.Clear();
    myReq.Method = "POST";
    myReq.ContentType = "application/x-www-form-urlencoded";
    myReq.ContentLength = xmlString.Length;
    using (StreamWriter sendingData = new
    StreamWriter(myReq.GetRequestStream()))
    {
    sendingData.Write(xmlString);
    sendingData.Flush();
    sendingData.Close();
    }

    WebResponse myResponse = myReq.GetResponse();
    StreamReader responseStream = new StreamReader
    (myResponse.GetResponseStream());
    XmlDocument shippingXml = new XmlDocument();
    shippingXml.LoadXml(responseStream.ReadToEnd());

    responseStream.Close();
    myResponse.Close();Still getting the "The underlying connection was closed: Could not establish
    trust relationship for the SSL/TLS secure channel" error message, after a
    period of time.

    "carion1" <> wrote in message
    news:...
    > HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(upsRateUri);
    > myReq.Headers.Clear();
    > myReq.Method = "POST";
    > myReq.ContentType = "application/x-www-form-urlencoded";
    > myReq.ContentLength = xmlString.Length;
    >
    > using(StreamWriter sendingData = new
    > StreamWriter(myReq.GetRequestStream()))
    > {
    > sendingData.Write(xmlString);
    > sendingData.Flush();
    > }
    >
    > WebResponse myResponse = myReq.GetResponse();
    >
    > On Apr 19, 11:07 am, "Joel Barsotti" <> wrote:
    >> I'm working on shipping rate calculator going back and forth via XML. The
    >> thing I'm confused about is that the code works, but after a few hours
    >> and I
    >> don't know how many requests, I start getting the error "The underlying
    >> connection was closed: Could not establish trust relationship for the
    >> SSL/TLS secure channel." I can't imagine UPS's certificate is bad.
    >>
    >> Here's my code, let me know if you see any glaring issues.
    >>
    >> HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(upsRateUri);
    >> myReq.Headers.Clear();
    >> myReq.Method = "POST";
    >> myReq.ContentType = "application/x-www-form-urlencoded";
    >> myReq.ContentLength = xmlString.Length;
    >> StreamWriter sendingData = new StreamWriter(myReq.GetRequestStream());
    >> sendingData.Write(xmlString);
    >> sendingData.Close();
    >> WebResponse myResponse = myReq.GetResponse();

    >
    >
    Joel Barsotti, Apr 20, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. C.W.
    Replies:
    1
    Views:
    5,932
  2. Jim Butler
    Replies:
    7
    Views:
    7,383
    Steven Cheng[MSFT]
    Jul 12, 2006
  3. Ghislain Tanguay
    Replies:
    3
    Views:
    199
    suresh g
    Sep 3, 2004
  4. C.W.
    Replies:
    1
    Views:
    162
  5. Joel Barsotti
    Replies:
    0
    Views:
    125
    Joel Barsotti
    Apr 19, 2007
Loading...

Share This Page