Error consuming Web API

Hello, in an ASP.NET MVC web project I'm 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 attempts 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
 [SocketException (0x274d): Nenhuma conexão pôde ser feita porque a máquina de destino as recusou ativamente]
   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 the Web API action timeout now?

asked by anonymous 31.07.2015 / 15:04

1 answer


Edmar, I went through this problem yesterday.

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

  • The API is not running. Normally, in my experience, I use the local IP port assigning a port when the API is running through IIS Express, hence the API project should be run, usually, by Visual Studio that starts the site in IIS Express.
  • The address to access the API has changed and is no longer In this case, you need to check the new address in the API project in Visual Studio.
  • If reason 2 occurred, you will need to update the API access setting in the web.config file of your project that accesses the API.

    31.07.2015 / 15:17