I have some code that send a simple xml web request. It is called from a windows service. Sometimes the service starts throwing exceptions (System.Net.WebException: The operation has timed out) and a restart of the service fixes the issue. Here is the code:
public bool PerformXmlRequest(string xml)
{
var httpRequest = (HttpWebRequest)WebRequest.Create(_url);
httpRequest.Method = "POST";
httpRequest.ContentType = "text/xml";
using (var xmlWriter = new StreamWriter(httpRequest.GetRequestStream(), Encoding.UTF8))
{
xmlWriter.WriteLine(xml);
}
using (var httpResponse = (HttpWebResponse)httpRequest.GetResponse())
{
return httpResponse.StatusDescription == "OK";
}
}
Is there anything obviously wrong with it that might be causing this issue?