Error while consuming Web API

Asked

Viewed 3,333 times

4

Hello, in an ASP.NET MVC web project I am trying to consume an API that is a Web API project, the two applications are running on the same server.

When I access the MVC application error occurs when this application tries to consume the Web API, the following error occurs:

Nenhuma conexão pôde ser feita porque a máquina de destino as recusou ativamente 127.0.0.1:24777
 [SocketException (0x274d): Nenhuma conexão pôde ser feita porque a máquina de destino as recusou ativamente 127.0.0.1:24777]
   System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult) +6641121
   System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) +271

[WebException: Impossível conectar-se ao servidor remoto]
   System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context) +2263386
   System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar) +106

[HttpRequestException: An error occurred while sending the request.]

Can it now be timeout of the Web API action?

  • Being a Socketexception, it seems to me to be a problem of connection to that address/port (127.0.0.1:24777). Have you tested to see if the service is in the air and can it even be accessed from this door? Try to consume some of the services using Postman (www.getpostman.com)? The result there can help us better understand the problem.

  • It no longer had this address in the application, but at the time of posting for some reason the files were not overwritten, so I deleted all the files and pasted again and stopped this error, but now this error is occurring: A task has been canceled. Description: An untreated exception occurred during the execution of the current web request. Examine stack tracking for more information about the error and where it originated in the code. Exception Details: System.Threading.Tasks.Taskcanceledexception: A task has been cancelled

  • Can it now be timeout of the Web API action?

1 answer

3

Edmar, I went through this problem yesterday.

The first action you need to take is to know which address the API is at. By the bug description, your project is trying to access it at 127.0.0.1:24777, but did not find it. This can occur for 2 reasons:

  1. The API is not running. Normally, in my experience, I use the local IP by assigning a port when the API is running on IIS Express, hence the API project should normally be run by Visual Studio starting the site on IIS Express.
  2. The address to access the API has changed and is no longer 127.0.0.1:24777. In this case, you need to check the new address in the API project in Visual Studio.

If motive 2 has occurred, you will need to update the API access setting in your project’s web.config file that accesses the API.

  • I no longer had this address in the application, but at the time of posting for some reason the files were not overwritten, so I deleted all the files and pasted again and stopped this error, but now this error is occurring: A task has been canceled. Description: An untreated exception occurred during the execution of the current web request. Examine stack tracking for more information about the error and where it originated in the code. Exception Details: System.Threading.Tasks.Taskcanceledexception: A task has been cancelled.

  • Can it now be timeout of the Web API action?

  • From the description, it doesn’t look like timeout. Have you ever accessed this API before? It’s in development?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.