当我尝试发送/接收大量请求/响应时,Web服务(asmx)出现问题...我一直收到错误“基础连接已关闭:接收时发生意外错误“
HttpWebRequest request = HttpWebRequest.Create("https://test.smth.cin:443/ws/1.0") as HttpWebRequest;
request.KeepAlive = true;
request.Method = "POST";
request.ContentType = "text/xml; charset=utf-8";
request.ClientCertificates.Add(Cert);
request.Headers.Add("SOAPAction", @"https://test.smth.cin:443/ws/1.0" + p_SOAPAction);
request.Timeout = 2200000;
StreamWriter requestWriter = new StreamWriter(request.GetRequestStream(),System.Text.Encoding.UTF8);
requestWriter.Write(str_SOAP);
requestWriter.Flush();
requestWriter.Close();
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
Stream responsedata = response.GetResponseStream();
StreamReader responsereader = new StreamReader(responsedata);
WS_Response ws_r = new WS_Response();
XmlDocument WS_XML_Response = new XmlDocument();
byte[] encodedString = Encoding.UTF8.GetBytes(str_SOAP);
// Put the byte array into a stream and rewind it to the beginning
MemoryStream ms = new MemoryStream(encodedString);
ms.Flush();
ms.Position = 0;
WS_XML_Response.Load(ms);
我还在webconfig中设置<httpRuntime maxRequestLength="200000" executionTimeout="360000" />
,但我仍然收到错误。
有什么想法吗?
答案 0 :(得分:0)
请更改u maxRequestLenght = Int32.MaxValue();
这将是某个地方 = 2147481263
答案 1 :(得分:0)
当我在过去看到这个错误时,问题是响应XML无效并且由于在处理无效XML期间发生异常而关闭连接。我会尝试保存原始XML请求数据,然后根据Web服务的架构验证XML数据。你可能会发现响应XML中存在一些无效的东西导致连接被强制关闭。