【问题标题】:C# Sometimes Getting Error "The underlying connection was closed: A connection that was expected to be kept alive was closed by the server"C#有时会出现错误“底层连接已关闭:预期保持活动状态的连接已被服务器关闭”
【发布时间】:2017-10-20 10:42:33
【问题描述】:
var request = new RestRequest("api/Article/List/TotalCount/{CompanyID}", Method.POST) { RequestFormat = DataFormat.Json };
        request.AddParameter("CompanyID", CompanyID, ParameterType.UrlSegment);
        request.AddBody(filterData);
        var response = Client.Execute<GridViewCount>(request);
        if (response.Data == null)
            throw new Exception(response.ErrorMessage); //Here I am getting Error.

这是我编写的使用 RestSharp 调用 web api 的代码。

此代码运行良好,我的 Web API 代码也运行良好。但有时我会收到“底层连接已关闭:预期保持活动状态的连接已被服务器关闭”的错误消息

注意:这是 MVC 项目。

【问题讨论】:

  • 请参阅此Question 了解此错误的可能原因。

标签: c# .net asp.net-mvc iis asp.net-web-api


【解决方案1】:

这是一个错误,因为您已经调用了该代码两次。您很可能有一个静态类,或者您应该为该对象创建一个新实例

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-22
    • 2014-02-22
    • 1970-01-01
    • 2011-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多