Azure Maps - SSL connection could not be established

Vinod Shinde 1 Reputation point
2021-01-09T15:45:20.623+00:00

I have Azure App Service that calls Maps API but get following error. What i am missing?

The SSL connection could not be established, see inner exception.

Exception:
System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host..
---> System.Net.Sockets.SocketException (10054): An existing connection was forcibly closed by the remote host.
--- End of inner exception stack trace ---
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.GetResult(Int16 token)
at System.Net.Security.SslStream.<FillHandshakeBufferAsync>g__InternalFillHandshakeBufferAsync|182_0TIOAdapter
at System.Net.Security.SslStream.ReceiveBlobAsyncTIOAdapter
at System.Net.Security.SslStream.ForceAuthenticationAsyncTIOAdapter
at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Boolean async, Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Boolean async, Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.GetHttpConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.DiagnosticsHandler.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.SendAsyncCore(HttpRequestMessage request, HttpCompletionOption completionOption, Boolean async, Boolean emitTelemetryStartStop, CancellationToken cancellationToken)
at AzureMapsToolkit.Common.BaseServices.GetDataT
at AzureMapsToolkit.Common.BaseServices.ExecuteRequestT,U
at AzureMapsToolkit.AzureMapsServices.GetSearchAddress(SearchAddressRequest searchAddressRequest)

Azure Maps
Azure Maps
An Azure service that provides geospatial APIs to add maps, spatial analytics, and mobility solutions to apps.
736 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. IoTGirl 3,131 Reputation points Microsoft Employee
    2021-01-10T07:02:45.027+00:00

    I suspect that you are trying to connect at a lower security level. See https://learn.microsoft.com/en-us/azure/azure-maps/azure-maps-authentication and ensure you are not using TLS 1.0 or TLS 1.1.


  2. IoTGirl 3,131 Reputation points Microsoft Employee
    2021-01-19T17:48:54.9+00:00

    Can you provide a sample of the call you are making? Generally this can be caused by either calling at the wrong security level or malformed request.


  3. Vinod Shinde 1 Reputation point
    2021-01-19T17:52:01.327+00:00

    It works sometime and sometimes does not. Does not work when call comes from mobile device to App Service.

    private async Task<Point> GetGeoCordinatePointFromAzureMapsAsync(string searchAddress)
            {
                try
                {
                    var am = new AzureMapsToolkit.AzureMapsServices(_configuration[Constants.AzureMaps.Key]);
    
                    var searchAddressRequest = new SearchAddressRequest
                    {
                        Query = searchAddress,
                        Limit = 1
                    };
                    var resp = await am.GetSearchAddress(searchAddressRequest);
                    if (resp.Error != null)
                    {
                        //TODO: Handle Address Geo Coding Error
                    }
                    else
                    {
                        var firstResult = resp.Result.Results.FirstOrDefault();
                        if (firstResult != null)
                        {
                            return new Point(firstResult.Position.Lon, firstResult.Position.Lat);
                        }
                    }
                }
                catch(Exception ex)
                {
                    _logger.LogError(ex, "Error in Azure Maps Address: " + searchAddress);
                }
    
                return null;
            }
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.