我有一些代码可以发送一个简单的 xml web 请求。它是从 Windows 服务调用的。有时服务开始抛出异常(System.Net.WebException:操作已超时)并且重新启动服务可以解决问题。这是代码:
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";
}
}
有什么明显的问题可能导致这个问题吗?