的基础连接已关闭错误
问题描述:
是任何人都熟悉这个问题,我好像得到它每一个现在,然后在我的Web服务客户端:的基础连接已关闭错误
基础连接已关闭:接收时发生意外错误。无法从传输连接读取数据:现有连接被远程主机强制关闭。在System.Net.HttpWebRequest.GetRequestStream(TransportContext &上下文) 在System.Net.HttpWebRequest.GetRequestStream()
这是我使用的请求和响应Web服务代码:
public string GetWebResponse(string data, IOffer offer)
{
_loggingManager.LogProcess(offer, true, "Request", "Request", data, offer.OperatorCode, true);
DateTime start = DateTime.Now;
StringBuilder returnedXml = new StringBuilder();
string outputstring = string.Empty;
ASCIIEncoding encoding = new ASCIIEncoding();
StreamReader r = null;
/*try
{*/
if (!string.IsNullOrEmpty(data))
outputstring = Regex.Replace(data, "\\s+", " ");
outputstring = outputstring.Replace("utf-16", "utf-8");
string PostData = "xml=" + outputstring;
byte[] Bytedata = encoding.GetBytes(PostData);
//fixme
objWebHTTPReq = (HttpWebRequest)WebRequest.Create(GetEndpointAddress(offer));
objWebHTTPReq.ContentType = "application/x-www-form-urlencoded";
objWebHTTPReq.Accept = "text/html";
objWebHTTPReq.ContentLength = Bytedata.Length;
objWebHTTPReq.Method = "POST";
objWebHTTPReq.KeepAlive = false;
string httpOutput = objWebHTTPReq.Headers.ToString();
objStream = objWebHTTPReq.GetRequestStream();
objStream.Write(Bytedata, 0, Bytedata.Length);
objStream.Flush();
objStream.Close();
WebResponse resp = objWebHTTPReq.GetResponse();
r = new StreamReader(resp.GetResponseStream());
returnedXml.Append(r.ReadToEnd().Replace("xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"", "").Replace("<?xml version=\"1.0\" encoding=\"utf-8\" ?>", "").ToString());
_loggingManager.LogProcess(offer, true, "Response", "Response", returnedXml.ToString(), offer.OperatorCode, true);
return returnedXml.ToString();
/*}
catch (Exception ex)
{
return null;
// fixme
//return this.CreateErrorResponse("Handled exception:\n" + ex.ToString());
}
finally
{
if (!string.IsNullOrEmpty(outputstring))
outputstring.Remove(0);
if (returnedXml != null)
returnedXml.Remove(0, returnedXml.Length);
if (r != null)
r.Dispose();
}*/
}
答
尝试为您的Web服务调用设置.Timeout
。你
yourWebService.Timeout = -1;// never timeout.
也可以尝试在你的web.config设置executionTimeout
:
<configuration>
<system.web>
<httpRuntime maxRequestLength="4000"
executionTimeout="45"
</system.web>
</configuration>
+0
我会试试这个,看看它是否工作 - 有点难以重新 - 创建它作为它安装在服务器上,只发生零星! – TheLearner 2010-09-09 09:26:56
答
该消息是在时间相当误导。当没有路由到远程主机时,您可以获得相同的消息。
当您收到错误时,尝试在同一端口上使用telnet。如果这样的作品,它似乎是一个超时,如果你不能telnet那么这是一个连接问题(没有路由主机)
这听起来像是超时异常对我 – MUG4N 2010-09-09 08:26:15