Re: HttpWebRequest.GetRequestStream times out
- From: Joerg Jooss <news-reply@xxxxxxxxxxxxx>
- Date: Wed, 7 Jun 2006 21:20:35 +0000 (UTC)
Thus wrote Christer,
Hello.
Hope this is the right group to post to. If not, please let me know
where to
post.
I'm having a problem doing an HTTP POST to my payment provider during
load. During days with low load, no errors occur.
The code being executed is in a class library loaded by an ASP.NET
application.
The server machine is a 2003 Server Std Ed. w/SP1, Intel Xeon 2.8 GHz
with
2.5 GB RAM.
.NET version is 1.1. The mscorlib.dll has version 1.1.4322.2300, I
take it
that it means .NET SP1...
When I encounter this exception, this is printed in the log:
Payment Authorization failed (WebException): Timeout. Message: The
operation has timed-out.. Response: . Stack Trace: at
System.Net.HttpWebRequest.GetRequestStream()
at Payment.DoPaymentAuth()
I have tried to configure the machine.config file according to the
reccomendations at MSDN:
- Set maxConnection to 48 (12 * 4)
- Set maxWorkerThreads to 100
- Set minFreeThreads to 352 (88* 4)
How can I investigate this further?
I hope someone can help me with this.
Here is the code:
<code>
try
{
//The postString has value "cardno=XXX&expmon=06&expyear=06" etc.
byte[] sendData = Encoding.ASCII.GetBytes(postString);
int sendLength = sendData.Length;
HttpWebRequest httpReq = (HttpWebRequest)
WebRequest.Create(PAYMENT_AUTH_URI);
httpReq.Method = "POST";
httpReq.ContentType="application/x-www-form-urlencoded";
httpReq.ContentLength = sendLength;
httpReq.ConnectionGroupName = "PaymentGroup";
//Error comes here...
Stream sendStream = httpReq.GetRequestStream();
sendStream.Write(sendData,0,sendLength);
sendStream.Flush();
sendStream.Close();
sendStream = null;
WebResponse resp = httpReq.GetResponse();
Stream respstrm = resp.GetResponseStream();
int length = 1024;
byte[] Buffer = new byte[length];
int bytesRead = 0;
bytesRead = respstrm.Read(Buffer,0,length);
if(bytesRead > 0 )
{
postReturn = Encoding.ASCII.GetString(Buffer,0, bytesRead);
}
try
{
respstrm.Flush();
respstrm.Close();
respstrm = null;
}
catch(Exception e)
{
respstrm = null;
}
try
{
resp.Close();
resp = null;
}
catch(Exception e)
{
resp = null;
}
}
catch(System.Net.WebException we)
{
LogError("Order Id " + this.OrderId + ": Payment Authorization
failed
(WebException)(" +
DateTime.Now.ToString(dateformat) + "): " + we.Status.ToString()
+ ".
Message: " +
we.Message + ". Response: " + we.Response + ". Stack Trace: " +
we.StackTrace);
if(we.Status == WebExceptionStatus.Timeout)
{
postReturn = "Timeout";
}
else
{
postReturn = "Error";
}
}
catch(Exception ex)
{
postReturn = "Error";
}
return postReturn;
</code>
Thanks!
Save for the somewhat scary exception handling (sorry!) and the fact that you never read more than 1 kB of the response, the code should work. The question is: What times out? Writing to the request stream? Obtaining the response? Reading from the response stream? Can you recreate the failure during a load test?
Cheers,
--
Joerg Jooss
news-reply@xxxxxxxxxxxxx
.
- Follow-Ups:
- Re: HttpWebRequest.GetRequestStream times out
- From: Christer Brinchmsnn
- Re: HttpWebRequest.GetRequestStream times out
- References:
- HttpWebRequest.GetRequestStream times out
- From: Christer Brinchmsnn
- HttpWebRequest.GetRequestStream times out
- Prev by Date: Anyone have a NUnitASP replacement for VS2005?
- Next by Date: Speed - C++ or Delphi Native Code performance vs. .NET
- Previous by thread: HttpWebRequest.GetRequestStream times out
- Next by thread: Re: HttpWebRequest.GetRequestStream times out
- Index(es):
Relevant Pages
|