Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.

Reply
Thread Tools

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

 
 
Joel Barsotti
Guest
Posts: n/a
 
      04-19-2007
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();

 
Reply With Quote
 
 
 
 
George Ter-Saakov
Guest
Posts: n/a
 
      04-19-2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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();



 
Reply With Quote
 
 
 
 
Joel Barsotti
Guest
Posts: n/a
 
      04-19-2007
Yeah I was starting to suspect that may be the case.

"George Ter-Saakov" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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();

>
>

 
Reply With Quote
 
carion1
Guest
Posts: n/a
 
      04-19-2007
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" <(E-Mail Removed)> 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();



 
Reply With Quote
 
Joel Barsotti
Guest
Posts: n/a
 
      04-19-2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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" <(E-Mail Removed)> 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();

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. Joel Barsotti ASP .Net Web Services 0 04-19-2007 04:22 PM
"Underlying connection was closed. Could not establish trust relationship" error Anna Troiken ASP .Net Web Services 2 03-17-2007 10:40 PM
The underlying connection was closed: Could not establish secure channel for SSL/TLS. Jim Butler ASP .Net 7 07-12-2006 01:37 AM
The underlying connection was closed: Could not establish secure channel for SSL/TLS C.W. ASP .Net 1 08-15-2005 04:23 AM
The underlying connection as closed: Could not establish secure channel for SSL/TLS Ghislain Tanguay ASP .Net Web Services 3 09-03-2004 07:49 PM



Advertisments