【问题标题】:Web Service(asmx) ERROR - The underlying connection was closed: An unexpected error occurred on a receiveWeb Service(asmx) 错误 - 底层连接已关闭:接收时发生意外错误
【发布时间】:2012-09-24 17:26:20
【问题描述】:

当我尝试发送/接收大型请求/响应时,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" />,但仍然出现错误。

有什么想法吗?

【问题讨论】:

  • 我检查了提琴手,我总是得到“504 Gateway Timeout”...

标签: c# web-services


【解决方案1】:

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

这将在某个地方 =2,147,481,263

【讨论】:

    【解决方案2】:

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

    【讨论】:

    • 我检查了,XML 响应是有效的。我认为托管 Web 服务的服务器有问题。我与使用此网络服务的其他人进行了检查,他们也遇到了同样的问题...
    猜你喜欢
    • 2011-01-25
    • 2014-03-10
    • 2020-04-08
    • 2020-06-24
    相关资源
    最近更新 更多