Skip to main content

Notifications

Community site session details

Community site session details

Session Id : IQjQjmcJaHGXR5Zek/BC3J
Power Apps - Microsoft Dataverse
Unanswered

SSL connection could not be establish via REST API

Like (0) ShareShare
ReportReport
Posted on 21 Mar 2024 08:50:51 by 36

Hi I am trying to connect to Dataverse API using .NET Core. I was able to connect successfully via my local machine but getting the "ssl connection error" when deployed on our server. Is there any configuration needs to be done on firewall to be able to connect to dataverse api?

 

See error below:

 

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)

 

Here is my code:

 

var scope = new[] { $"https://{environment}.dynamics.com/.default" };
var webAPI = $"https://{environment}.dynamics.com/api/data/v{apiVersion}/";
var authority = $"https://login.microsoftonline.com/{tenantId}";

var clientApp = ConfidentialClientApplicationBuilder.Create(clientId)
.WithClientSecret(clientSecret)
.WithTenantId(tenantId)
.WithAuthority(authority)
.Build();

var authResult = clientApp.AcquireTokenForClient(scope).ExecuteAsync().Result;

using var httpClient = new HttpClient
{
BaseAddress = new Uri(webAPI),
Timeout = new TimeSpan(0, 0, 10)
};

httpClient.DefaultRequestHeaders.Add("OData-MaxVersion", "4.0");
httpClient.DefaultRequestHeaders.Add("OData-Version", "4.0");
httpClient.DefaultRequestHeaders.Add("Prefer", "odata.include-annotations=\"*\"");

httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authResult.AccessToken);

var response = httpClient.GetAsync("whoami").Result;

 

  • EricRegnier Profile Picture
    8,714 Most Valuable Professional on 21 Mar 2024 at 16:12:56
    Re: SSL connection could not be establish via REST API

    Hi @johnryanrobles,
    It's hard to say without knowing your Functions/service configuration which is most likely the issue; it could be a configuration with Azure (eg APIM, vnet). Are you able to isolate the issue and deploy to a public facing Function not hidden behind APIM or vnet? 
    Here would be the list of IP ranges to whitelist and URLs to allow:
    https://learn.microsoft.com/connectors/common/outbound-ip-addresses

    https://learn.microsoft.com/power-platform/admin/online-requirements

    Hope this helps...

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Leaderboard > Power Apps - Microsoft Dataverse

#1
mmbr1606 Profile Picture

mmbr1606 22 Super User 2025 Season 1

#2
stampcoin Profile Picture

stampcoin 19

#3
Michael E. Gernaey Profile Picture

Michael E. Gernaey 17 Super User 2025 Season 1

Overall leaderboard

Featured topics

Loading started