经过几天的搜索,我真的无法解决所描述的问题.希望这里会找到一个解决方案
在同一服务器上调用WCF服务时,我使用附加的代码.我在调用WebReq.GetRequestStream()时随机获取超时错误
当我检查netstat时,我看到连接保持打开状态,所以可能有问题,但是我不知道如何解决它
//request inicialization HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(url); WebReq.Method = "POST"; WebReq.ContentType = "application/json; charset=utf-8"; WebReq.ContentLength = buffer.Length; WebReq.Proxy = null; WebReq.KeepAlive = false; //also tried with true WebReq.AllowWriteStreamBuffering = false; //also tried with true //this produces an error using (Stream PostData = WebReq.GetRequestStream()) { PostData.Write(buffer,buffer.Length); PostData.Close(); } //open and read response HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse(); Stream Answer = WebResp.GetResponseStream(); StreamReader _Answer = new StreamReader(Answer); WebResp.Close(); //return string return _Answer.ReadToEnd();
超时在大概10秒的空闲时间之后抛出,而且在这行中还有五个左右的请求.真的找不到一个模式.