Re: HttpWebRequest.GetRequestStream times out



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


.



Relevant Pages

  • RE: HTTPS WebRequest and WebResponse
    ... > // Creates an HttpWebRequest for the specified URL. ... > // Displays all the headers present in the response received from the URI. ... > // Obtain a 'Stream' object associated with the response object. ... > StreamReader readStream = new StreamReader(ReceiveStream, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Read everything from socket
    ... There is no standard way to indicate a stream is finished ... line from the RETR command ... Or from the LIST command ... the actual byte length is given of the response steam. ...
    (perl.beginners)
  • HTTPS WebRequest and WebResponse
    ... // Creates an HttpWebRequest for the specified URL. ... // Displays all the headers present in the response received from the URI. ... // Obtain a 'Stream' object associated with the response object. ... StreamReader readStream = new StreamReader(ReceiveStream, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: HttpWebRequest.GetRequestStream times out
    ... When I encounter this exception, this is printed in the log: ... Stream sendStream = httpReq.GetRequestStream; ... you never read more than 1 kB of the response, ... The request timeout is set to 100 seconds, and the requests that time out ...
    (microsoft.public.dotnet.framework.performance)
  • Re: "Sucking" .txt files from the Internet
    ... The scraper spins a new thread ... Dim bufferAs Byte ... Dim BytesRead As Int32 = FileStream.Read ... I'd like to use an ASP.NET web application to download (or stream down) ...
    (microsoft.public.dotnet.framework.aspnet)

Quantcast