1
votes

API call from Azure App Service to API hosted on Azure VM

I am getting the following error message when My Azure Chat bot make calls to API which is hosted on Azure VM. My App Service/Web App Bot are both on the same resource group.

One or more errors occurred. (An attempt was made to access a socket in a way forbidden by its access permissions) ---> System.Net.Http.HttpRequestException: An attempt was made to access a socket in a way forbidden by its access permissions ---> System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken) --- End of inner exception stack trace --- at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken) at System.Threading.Tasks.ValueTask1.get_Result() at System.Net.Http.HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Threading.Tasks.ValueTask1.get_Result() at System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync(ValueTask1 creationTask) at System.Threading.Tasks.ValueTask1.get_Result()
at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)

I am getting this error only when API calls are from azure.My Chat bot is developed with .net core 2.2/bot framework v4 /C# . My VM API is using port 80.

Appreciate your suggestions to resolve this error.

1
Have you tried adding an inbound traffic rule to your VM for port 80 as per this guide?Matt Stannett

1 Answers

1
votes

For the socket forbidden error, you properly could check the followings:

  • The API port 80 is listening on the hosted VM.
  • The port is not using by other application, service or process. On windows VM, you could run netstat -anbo in CMD as the administrator account to verify this.
  • Security or firewall issue. If you have NSG associated with this VM subnet or VM network interface, you need to add an inbound rule to allow port 80 from your web app service. Also, you have to enable this inbound port on the VM firewall if you a firewall inside the VM. Refer to Diagnose a virtual machine network traffic filter problem.
  • Access Restrictions in the Azure app service. Check if any IP rule restriction is to deny the access outside app service.

Hope this could help you.