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;

Report
All responses (
Answers (