0
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.

This is the code I have written to call web api using RestSharp.

This code works fine and my Web API code works fine as well. But sometimes I get Error that "The underlying connection was closed: A connection that was expected to be kept alive was closed by the server"

note: this is MVC project.

Victor
  • 65
  • 1
  • 7
  • Please refer to this [Question](http://stackoverflow.com/questions/14052218/connection-that-was-expected-to-be-kept-alive-was-closed-by-the-server-in-asp-ne) for possible reasons for this error. – mmushtaq May 20 '17 at 11:09

1 Answers1

0

That's a mistake, because you've been calling that code twice. You most likely have a static class or should you create a new instance for the object

Marinpietri
  • 112
  • 3
  • 8