PC Review


Reply
Thread Tools Rate Thread

timeout on http post when multiple posts in parallel

 
 
Wilfried Mestdagh [MapPoint MVP]
Guest
Posts: n/a
 
      25th Jun 2009

Hello,

I do a HTTP POST in a thread with following code (only relevant copied here):

Cli cli = new Cli();
Thread cliThread = new Thread(new ThreadStart(cli.Run));
cliThread.Start();

the Cli class is like this:

public void Run()
{
HttpWebResponse webResponse;
try {
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(Url);
req.Timeout = timeout; // set to 10 seconds
req.Method = "POST";
StreamWriter stOut = new StreamWriter(req.GetRequestStream(),
System.Text.Encoding.Default);
stOut.Write(xml);
stOut.Close();
webResponse = (HttpWebResponse)req.GetResponse();
statuscode = (int)webResponse.StatusCode;
StreamReader stIn = new StreamReader(webResponse.GetResponseStream());
string response = stIn.ReadToEnd();
stIn.Close();
} catch (WebException webEx) {

This works fine with one thread. But when I do several requests in parallel
then I get webexception "the operation timed out". I checked with a tool (a
kind of proxy that log all TCP traffic) and the server is giving immediatly a
200 and a page for "each" POST. So the data is received every time. But wy is
the timeout generated?

Can someone advice here?

--
rgds, Wilfried [MapPoint MVP]
http://www.mestdagh.biz
 
Reply With Quote
 
 
 
 
Wilfried Mestdagh [MapPoint MVP]
Guest
Posts: n/a
 
      6th Jul 2009

Hi,

Thank you for your answer. The multiple threads are started with this code
called several times from within the main thread:
Cli cli = new Cli();
Thread cliThread = new Thread(new ThreadStart(cli.Run));
cliThread.Start();

So the "Run()" method of the Cli class is running in a separated thread
context. Question: do I still need the BeginGetRequestStream instead of
GetRequestStream ??? Because the code is already executed in his own thread.
Or am I missing something?

--
rgds, Wilfried [MapPoint MVP]
http://www.mestdagh.biz


"Angel J. Hernández M." wrote:

> Hi Wilfried,
>
> In your previous example I just see one thread, but anyways if you want to
> do it with multiple threads then you need to do it in an Asynchronous way.
> Try implementing BeginGetRequestStream instead of GetRequestStream
>
> http://msdn.microsoft.com/en-us/libr...eststream.aspx
>
>
> Regards,
>
>
>
> --
> Angel J. Hernández M
> MCP,MCAD,MCSD,MCDBA
> Microsoft MVP
> http://msmvps.com/blogs/angelhernandez
> *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
> http://www.customware.net
> Technical Solutions Architect
>
>
>
>
> "Wilfried Mestdagh [MapPoint MVP]"
> <(E-Mail Removed)> wrote in message
> news:C4DE9799-D486-4C24-935E-(E-Mail Removed)...
> > Hello,
> >
> > I do a HTTP POST in a thread with following code (only relevant copied
> > here):
> >
> > Cli cli = new Cli();
> > Thread cliThread = new Thread(new ThreadStart(cli.Run));
> > cliThread.Start();
> >
> > the Cli class is like this:
> >
> > public void Run()
> > {
> > HttpWebResponse webResponse;
> > try {
> > HttpWebRequest req = (HttpWebRequest)WebRequest.Create(Url);
> > req.Timeout = timeout; // set to 10 seconds
> > req.Method = "POST";
> > StreamWriter stOut = new StreamWriter(req.GetRequestStream(),
> > System.Text.Encoding.Default);
> > stOut.Write(xml);
> > stOut.Close();
> > webResponse = (HttpWebResponse)req.GetResponse();
> > statuscode = (int)webResponse.StatusCode;
> > StreamReader stIn = new
> > StreamReader(webResponse.GetResponseStream());
> > string response = stIn.ReadToEnd();
> > stIn.Close();
> > } catch (WebException webEx) {
> >
> > This works fine with one thread. But when I do several requests in
> > parallel
> > then I get webexception "the operation timed out". I checked with a tool
> > (a
> > kind of proxy that log all TCP traffic) and the server is giving
> > immediatly a
> > 200 and a page for "each" POST. So the data is received every time. But wy
> > is
> > the timeout generated?
> >
> > Can someone advice here?
> >
> > --
> > rgds, Wilfried [MapPoint MVP]
> > http://www.mestdagh.biz

>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
IIS Timeout , Web Config Timeout, Page Timeout. =?Utf-8?B?TWlrZSBNb29yZQ==?= Microsoft Dot NET 0 17th Jan 2006 07:52 PM
Parallel to USB: HP Bi-Tronics Parallel Interface" ? casteele95thbgheavy@yahoo.com Printers 2 9th Jan 2006 08:50 PM
Parallel port to Parallel port =?Utf-8?B?RmxleHVz?= Windows XP Networking 1 23rd Aug 2005 07:18 AM
Can't browse to http://localhost, http://127.0.0.1, http://computer_name anymore BRIAN DUFF Windows XP Networking 0 16th Jan 2004 06:45 AM
Does parallel to usb work for usb printer to parallel port? Don in WNY Printers 2 14th Jul 2003 11:04 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:45 AM.