Slow HttpWebRequest using https

  • Thread starter Soeren S. Joergensen
  • Start date
S

Soeren S. Joergensen

Hi,

From a win-service I do a HttpWebRequest to a secure url with some
parameters to get some simple data from a remote system used later on in a
worker thread.

When making the request from my code it takes about 10-12 secs to complete,
but doing same request in my browser takes less than 1 sec.
Can anyone explain this delay from within my code ??

Win-service is running using LocalSystem account and Assembly has a
StrongName with FullTrust assigned.

In advance, thanx...

Soren
 
A

Alvin Bruney - ASP.NET MVP

Can you time exactly what line is causing the slow down? You shouldn't
assume that it is the actual call because the time span seems very
unreasonable to me.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
 
S

Soren S. Jorgensen

Hi Alvin,

Well - the call that takes way to long is actually the request it self!
Code for the request follows below:

string uri =
"https://host.domain.com/Appl/report?cmd=Test&transid=HHDGQTSREGDP";

HttpWebRequest req = WebRequest.Create(uri) as HttpWebRequest;
if(req != null)
{
Console.WriteLine(DateTime.Now);

res = req.GetResponse() as HttpWebResponse; // <<<< This line takes
10-15 secs ???
if(res != null)
{
Console.WriteLine(DateTime.Now);

if(res.StatusCode == HttpStatusCode.OK)
{
XmlDocument doc = new XmlDocument();
doc.Load(res.GetResponseStream());
// Do stuff...
}
}
}

Very, very slow :-/

Kr. Soren

Alvin Bruney - ASP.NET MVP said:
Can you time exactly what line is causing the slow down? You shouldn't
assume that it is the actual call because the time span seems very
unreasonable to me.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------



Soeren S. Joergensen said:
Hi,

From a win-service I do a HttpWebRequest to a secure url with some
parameters to get some simple data from a remote system used later on in
a
worker thread.

When making the request from my code it takes about 10-12 secs to complete,
but doing same request in my browser takes less than 1 sec.
Can anyone explain this delay from within my code ??

Win-service is running using LocalSystem account and Assembly has a
StrongName with FullTrust assigned.

In advance, thanx...

Soren
 
A

Alvin Bruney - ASP.NET MVP

What kind of ping times are you looking at for that server? Are you doing
anything funky with SSL/Certificates? Also, modify your code to set a
timeout on the webrequest. If it times out, it will throw an exception so
you should know exactly if the request itself is running into trouble. I've
never seen that kind of behavior from a machine that can connect and
retrieve data from a URI.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------



Soren S. Jorgensen said:
Hi Alvin,

Well - the call that takes way to long is actually the request it self!
Code for the request follows below:

string uri =
"https://host.domain.com/Appl/report?cmd=Test&transid=HHDGQTSREGDP";

HttpWebRequest req = WebRequest.Create(uri) as HttpWebRequest;
if(req != null)
{
Console.WriteLine(DateTime.Now);

res = req.GetResponse() as HttpWebResponse; // <<<< This line takes
10-15 secs ???
if(res != null)
{
Console.WriteLine(DateTime.Now);

if(res.StatusCode == HttpStatusCode.OK)
{
XmlDocument doc = new XmlDocument();
doc.Load(res.GetResponseStream());
// Do stuff...
}
}
}

Very, very slow :-/

Kr. Soren

Alvin Bruney - ASP.NET MVP said:
Can you time exactly what line is causing the slow down? You shouldn't
assume that it is the actual call because the time span seems very
unreasonable to me.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------



Soeren S. Joergensen said:
Hi,

From a win-service I do a HttpWebRequest to a secure url with some
parameters to get some simple data from a remote system used later on in
a
worker thread.

When making the request from my code it takes about 10-12 secs to complete,
but doing same request in my browser takes less than 1 sec.
Can anyone explain this delay from within my code ??

Win-service is running using LocalSystem account and Assembly has a
StrongName with FullTrust assigned.

In advance, thanx...

Soren
 
D

dina_vr

Add the following before you create your HttpWebRequest object. I
also had a slow response from a HTTPs through a proxy and adding the
following fixed it.

System.Net.ServicePointManager.Expect100Continue = false;

Thanks
Dhina
 
J

Joerg Jooss

Add the following before you create your HttpWebRequest object. I
also had a slow response from a HTTPs through a proxy and adding the
following fixed it.

System.Net.ServicePointManager.Expect100Continue = false;

That shouldn't make a difference, the OP sends a GET request.

Cheers,
 
S

Soren S. Jorgensen

Hi Alvin,

No trouble in ping, less than 50 ms for replies.

I'm not doing anything else than show in earlier post, except that I call
Dns.GetHostEntry(uri.Host) to make sure server is available, which returns
as excepted. No funny stuff about certs, or whatever.

No need to set a timeout - default is 100 secs. - as long as I can't relay
on the call to finish in reasonble time this will do. When it works as it
should I'll change timeout to something more appropreate, like 10 secs.

I've never seen anything like this either, that's why the post :)

Soren

Alvin Bruney - ASP.NET MVP said:
What kind of ping times are you looking at for that server? Are you doing
anything funky with SSL/Certificates? Also, modify your code to set a
timeout on the webrequest. If it times out, it will throw an exception so
you should know exactly if the request itself is running into trouble.
I've
never seen that kind of behavior from a machine that can connect and
retrieve data from a URI.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------



Soren S. Jorgensen said:
Hi Alvin,

Well - the call that takes way to long is actually the request it self!
Code for the request follows below:

string uri =
"https://host.domain.com/Appl/report?cmd=Test&transid=HHDGQTSREGDP";

HttpWebRequest req = WebRequest.Create(uri) as HttpWebRequest;
if(req != null)
{
Console.WriteLine(DateTime.Now);

res = req.GetResponse() as HttpWebResponse; // <<<< This line takes
10-15 secs ???
if(res != null)
{
Console.WriteLine(DateTime.Now);

if(res.StatusCode == HttpStatusCode.OK)
{
XmlDocument doc = new XmlDocument();
doc.Load(res.GetResponseStream());
// Do stuff...
}
}
}

Very, very slow :-/

Kr. Soren

Alvin Bruney - ASP.NET MVP said:
Can you time exactly what line is causing the slow down? You shouldn't
assume that it is the actual call because the time span seems very
unreasonable to me.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------



Hi,

From a win-service I do a HttpWebRequest to a secure url with some
parameters to get some simple data from a remote system used later on in
a
worker thread.

When making the request from my code it takes about 10-12 secs to
complete,
but doing same request in my browser takes less than 1 sec.
Can anyone explain this delay from within my code ??

Win-service is running using LocalSystem account and Assembly has a
StrongName with FullTrust assigned.

In advance, thanx...

Soren
 
S

Soren S. Jorgensen

Hi all,

Ok - found the error (or what ever)

Setting System.Net.ServicePointManager.CheckCertificateRevocationList =
false made a big difference, seems my customer has a big CRL or a slow cert
server

Thanx...

Kr. Soren
 
A

Alvin Bruney - ASP.NET MVP

Nice.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
 

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