Hi,
I am facing an error "The request was aborted: Could not create SSL/TLS secure channel." on calling an API to send data to a 3rd party application.
I found similar queries on community but those fixes doesn't worked for me.
The version of TLS is 1.2 on my local hosted VM. (Note: it doesn't work on UAT and Production as well).
please help me out with this one.
Thanks
Here is code that I am using:
try { httpHeader = new System.Net.WebHeaderCollection(); new InteropPermission(InteropKind::ClrInterop).assert(); clrObj = System.Net.WebRequest::Create("URL"); request = clrObj; // adding headers byteStr = System.Convert::ToBase64String(System.Text.Encoding::Default.GetBytes(user ":" pass)); httpHeader.Add("Accept-Version", "V2"); httpHeader.Add("Clearance-Status", "1"); httpHeader.Add("Accept-Language", "en"); httpHeader.Add("Authorization", 'Basic ' byteStr); request.set_Headers(httpHeader); request.Method = "POST"; request.ContentType = "application/json"; requestStream = request.GetRequestStream(); streamWriter = new System.IO.StreamWriter(request.GetRequestStream()); streamWriter.Write(jsonBody); // writing JSON response = request.GetResponse(); streamWriter.Flush(); streamWriter.Close(); System.IO.StreamReader streamRead = new System.IO.StreamReader(response.GetResponseStream()); Map responseMap = RetailCommonWebAPI::getMapFromJsonString(streamRead.ReadToEnd()); MapEnumerator mapenum = responseMap.getEnumerator(); /* Some code to validate the result */ } catch { //exception ex = CLRInterop::getLastException().GetBaseException(); error(ex.get_Message()); }
We talked to Microsoft support it comes out to be the ciphers that were not configured on D365 FnO VMs.
Configuring those resolved the issue.
Verify that the system trusts the issuer of the certificate.
I would also review registry settings (Transport Layer Security (TLS) best practices with the .NET Framework > Configuring security via the Windows Registry), remove SecurityProtocol assignment and try if it makes a difference.
You can also look at previous discussions (such as this or this). There are a few more ideas about possible reasons and ways of debugging. And ask in an appropriate forum if nothing helps.
try { string serviceOperationPath = "URL"; ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12; //Serialize the object into stream before sending it to the remote server string json = JsonConvert.SerializeObject(apiRequest); byte[] data = Encoding.UTF8.GetBytes(json); HttpClient httpClient = new HttpClient(); httpClient.BaseAddress = new Uri("BASEURI"); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.Default.GetBytes(complianceCSID ":" complianceSecret))); httpClient.DefaultRequestHeaders.Add("Accept-Version", "V2"); httpClient.DefaultRequestHeaders.Add("Accept-Language", "en"); httpClient.DefaultRequestHeaders.Add("Clearance-Status", "1"); HttpRequestMessage httpRequest = new HttpRequestMessage(HttpMethod.Post, "URLPOSTFIX"); var content = new StringContent(json, Encoding.UTF8, "application/json"); httpRequest.Content = content; var res = httpClient.SendAsync(httpRequest).Result; } catch (Exception ex) { }
Here is the part of code that calls the API in C# Application
No, your initial code doesn't contain the fix that I suggested in my second reply.
Also, it's not the C# code we're discussed in last replies. I understand that you want to use X++ code, but now we're talking about your test app written in C#.
The code is present in my initial question.
I created C# just to check if that work in C# or not but it didn't worked in VM but it worked in my laptop with windows 10 (22H2 Build 19045.2965).
My initial code is in F&O that I want to use.
I believe TLS 1.2. is enabled in Windows Server 2019 by default.
Can you show us your current code (with Tls12 enabled), so we can review that it was done correctly?
Since you have a problem with a pure C# application and it's not about F&O, consider asking in a .NET forum instead.
s the version of OS
Version of the operating system where you're executing your code and getting the error. I'm assuming it's Windows Server.
[/quote]Version of the operating system where you're executing your code and getting the error. I'm assuming it's Windows Server.
HTTP Client also gave same error.
My windows 10 version or windows server version?
.NET framework version is 4.8
I only tried it with WebRequest only.
I'll try it again with httpClient and will update you shortly.
André Arnaud de Cal...
291,996
Super User 2025 Season 1
Martin Dráb
230,853
Most Valuable Professional
nmaenpaa
101,156