0

我在尝试发送/接收大型请求/响应时遇到 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);

我也在<httpRuntime maxRequestLength="200000" executionTimeout="360000" />webconfig 中进行了设置,但仍然出现错误。

有任何想法吗?

4

2 回答 2

0

当我过去看到这个错误时,这是​​一个问题,响应 XML 无效并且连接由于在处理无效 XML 期间发生的异常而关闭。我会尝试保存原始 XML 请求数据,然后根据您的 Web 服务的架构验证 XML 数据。您可能会发现响应 XML 中有一些无效的内容导致连接被强制关闭。

于 2012-09-27T18:12:04.320 回答
0

请更改您的 maxRequestLenght=Int32.MaxValue();

这将是某处= 2,147,481,263

于 2012-09-24T17:32:16.367 回答