System.AggregateException : HttpRequestException & SocketException(No connection could be made because the target machine actively refused it)

0

I am calling web API in my mvc .net core project in following manner,

client = new HttpClient();
client.BaseAddress = new Uri(url);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

Employee Returnmodel = client.GetAsync("api/employee/find/" + Convert.ToInt32(id) + "").Result.Content.ReadAsAsync<Employee>().Result; //throws exception

Above Code throws following exception

System.AggregateException
HResult=0x80131500
Message=One or more errors occurred.
Source=System.Private.CoreLib
StackTrace:
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at EmployeeManagent.Web.Controllers.EmployeeController.EmployeeController.EmployeeData(User model, Nullable`1 id) in F:\C Partition\Documents\Tejas Training\EmployeeManagementSystem\EmployeeManagent.Web\EmployeeManagent.Web\Controllers\EmployeeController\EmployeeController.cs:line 61
at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__12.MoveNext()

Inner Exception 1:
HttpRequestException: No connection could be made because the target machine actively refused it

Inner Exception 2:
SocketException: No connection could be made because the target machine actively refused it
asp.net-core-webapi
dotnet-httpclient
asked on Stack Overflow Nov 16, 2018 by Tejas

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0