使用httpwebrequest时定期超时
-
09-10-2019 - |
题
我有一些发送简单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";
}
}
显然有什么问题可能导致这个问题吗?
解决方案
我没有发现通话代码没有错。
错误是由客户端代码生成的,还是来自服务?
如果来自服务是需要修复的服务,无论您发送什么服务,服务都不应超时,它应该在更受控的Maner中失败,给出Beter错误消息。
不隶属于 StackOverflow