Empty Response using HttpWebRequest.GetResponse() after client's web.config updated

  • Thread starter Thread starter Martin
  • Start date Start date
M

Martin

Hi,

I've struggled with this for a couple of days now and hopefully
someone can help:

I have a test harness web application sending XML over HTTP to an aspx
page in a seperate web application.
This aspx page simply writes some text to the response.

The problem is that, should the web.config file of the second
application be updated, then the next request made by the test harness
will receive an empty response (Response.ContentLength = -1).

I've tried making the requests from a winforms app as well and the
same problem occurs. I think it is something to do with the ASP.Net
process restarting after the web.config is changed.

Sample code:
WinForms app, where
'bytes' is the byte[] of info i want to send
myurl is the url of my aspx page
GetResponseString() simply extract the contents of the Respone.

private void btnSendRequest_Click(object sender, System.EventArgs e)
{
try
{
WebRequest request =
(HttpWebRequest)HttpWebRequest.Create(myurl));
request.ContentLength = bytes.Length;
request.ContentType = "text/xml";
request.Method = "POST";

using (Stream stream = request.GetRequestStream())
{
stream.Write(bytes, 0, bytes.Length);
}

WebResponse response = request.GetResponse();
string strResponse = GetResponseString(response);
txtResponse.Text = strResponse;
}
catch(Exception ex)
{
txtResponse.Text = "Exception: " + ex.Message;
}
}

Sample web form:

public class WebForm1 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
Response.Write("test response string")
}

...
}

As mentioned earlier, when I change the web.config file of the web
application containing WebForm1, then the first request to that page
via the test harness will have a Response.ContentLength = -1.

I could make the client resend the request, but since the client will
be a legacy system in production i would rather handle the problem
within the web application.

I'm hoping theres a simple solution, thanks in advance for any help,
Martin
 
Back
Top