Error: The request was aborted: Could not create SSL/TLS secure channel- In nav 2016

devanshu_chaudhary
Member Posts: 7
Hello Experts,
Error Message:
A call to System.Net.HttpWebRequest.GetResponse failed with this message: The request was aborted: Could not create SSL/TLS secure channel.
I am facing this error while working on E-Invoicing integration.I have doubt in Security Protocol Type but used others also like Tls,Tls11,Tls12,Tls13,Ssl3 but still same error.Plz help
My Code is:
//GetJson;
CLEAR(DataExch);
CreateJSONSalesInvoice(Rec);
IF FILE.EXISTS(GetClientFile + 'J.txt') THEN
ERASE(GetClientFile + 'J.txt');
FL.CREATE(GetClientFile + 'J.txt');
FL.CREATEOUTSTREAM(OutStrm);
OutStrm.WRITETEXT(FORMAT(Json));
FL.CLOSE;
IF CONFIRM('Do you want view the JSON ?') THEN
//MESSAGE('%1',FORMAT(Json));
IF NOT CONFIRM(FORMAT(Json)) THEN
EXIT;
//To Get Request No.
EInvIntegrationSetup.GET;
HttpWebRequestMgt.Initialize(FORMAT(EInvIntegrationSetup."Generate E-Invoice URL"));
HttpWebRequestMgt.DisableUI;
ServicePMgr.Expect100Continue:=TRUE;
ServicePMgr.SecurityProtocol(SecurityProtocal.Tls12);
HttpWebRequestMgt.SetMethod('POST');
HttpWebRequestMgt.SetReturnType('application/json');
HttpWebRequestMgt.SetContentType('application/json');
HttpWebRequestMgt.AddHeader('Authorization',FORMAT(EInvIntegrationSetup."Bearer Token"));
HttpWebRequestMgt.AddBody(GetClientFile + 'J.txt');
TempBlob.INIT;
TempBlob.Blob.CREATEINSTREAM(ResponseInStream_L);
IF HttpWebRequestMgt.GetResponse(ResponseInStream_L,HttpStatusCode_L,ResponseHeaders_L) THEN BEGIN
ResponseInStream_L.READ(ResponseText);
//MESSAGE('%1',ResponseText);
Json := ResponseText;
ReadJSon(Json,DataExch);
IF GetJsonNodeValue('status.message') = 'Error' THEN
ERROR(GetJsonNodeValue('datalist..error.message.message'));
ReqNo := '';
ReqNo := GetJsonNodeValue('request');
SLEEP(2000);
//To Get E-Invoice
//MESSAGE('%1',FORMAT(EInvIntegrationSetup."Get Url") + GetJsonNodeValue('request'));
HttpWebRequestMgt.Initialize(FORMAT(EInvIntegrationSetup."Get Url") + ReqNo);
HttpWebRequestMgt.DisableUI;
HttpWebRequestMgt.SetMethod('GET');
HttpWebRequestMgt.SetReturnType('application/json');
HttpWebRequestMgt.SetContentType('application/json');
HttpWebRequestMgt.AddHeader('Authorization',FORMAT(EInvIntegrationSetup."Bearer Token"));
ServicePMgr.Expect100Continue:=TRUE;
ServicePMgr.SecurityProtocol(SecurityProtocal.Tls12);
TempBlob2.INIT;
TempBlob2.Blob.CREATEINSTREAM(ResponseInStream_L);
IF HttpWebRequestMgt.GetResponse(ResponseInStream_L,HttpStatusCode_L,ResponseHeaders_L) THEN BEGIN
ResponseInStream_L.READ(ResponseText2);
//MESSAGE('%1',ResponseText2);
Json2 := ResponseText2;
ReadJSon(Json2,DataExch);
IF GetJsonNodeValue('status.message') = 'Error' THEN
ERROR(GetJsonNodeValue('datalist..error.message.message'));
InsertResponse_New(Rec."No.",1,'');
COMMIT;
IF GetJsonNodeValue('datalist..einv.Irn') <> '' THEN
MESSAGE(Text50000,Rec."No.")
ELSE
//ERROR('E-Invoice not generated.');
MESSAGE('E-Invoice Request No. Updated !!');
END;
END ELSE
ERROR('E-Invoice not generated.');
Error Message:
A call to System.Net.HttpWebRequest.GetResponse failed with this message: The request was aborted: Could not create SSL/TLS secure channel.
I am facing this error while working on E-Invoicing integration.I have doubt in Security Protocol Type but used others also like Tls,Tls11,Tls12,Tls13,Ssl3 but still same error.Plz help
My Code is:
//GetJson;
CLEAR(DataExch);
CreateJSONSalesInvoice(Rec);
IF FILE.EXISTS(GetClientFile + 'J.txt') THEN
ERASE(GetClientFile + 'J.txt');
FL.CREATE(GetClientFile + 'J.txt');
FL.CREATEOUTSTREAM(OutStrm);
OutStrm.WRITETEXT(FORMAT(Json));
FL.CLOSE;
IF CONFIRM('Do you want view the JSON ?') THEN
//MESSAGE('%1',FORMAT(Json));
IF NOT CONFIRM(FORMAT(Json)) THEN
EXIT;
//To Get Request No.
EInvIntegrationSetup.GET;
HttpWebRequestMgt.Initialize(FORMAT(EInvIntegrationSetup."Generate E-Invoice URL"));
HttpWebRequestMgt.DisableUI;
ServicePMgr.Expect100Continue:=TRUE;
ServicePMgr.SecurityProtocol(SecurityProtocal.Tls12);
HttpWebRequestMgt.SetMethod('POST');
HttpWebRequestMgt.SetReturnType('application/json');
HttpWebRequestMgt.SetContentType('application/json');
HttpWebRequestMgt.AddHeader('Authorization',FORMAT(EInvIntegrationSetup."Bearer Token"));
HttpWebRequestMgt.AddBody(GetClientFile + 'J.txt');
TempBlob.INIT;
TempBlob.Blob.CREATEINSTREAM(ResponseInStream_L);
IF HttpWebRequestMgt.GetResponse(ResponseInStream_L,HttpStatusCode_L,ResponseHeaders_L) THEN BEGIN
ResponseInStream_L.READ(ResponseText);
//MESSAGE('%1',ResponseText);
Json := ResponseText;
ReadJSon(Json,DataExch);
IF GetJsonNodeValue('status.message') = 'Error' THEN
ERROR(GetJsonNodeValue('datalist..error.message.message'));
ReqNo := '';
ReqNo := GetJsonNodeValue('request');
SLEEP(2000);
//To Get E-Invoice
//MESSAGE('%1',FORMAT(EInvIntegrationSetup."Get Url") + GetJsonNodeValue('request'));
HttpWebRequestMgt.Initialize(FORMAT(EInvIntegrationSetup."Get Url") + ReqNo);
HttpWebRequestMgt.DisableUI;
HttpWebRequestMgt.SetMethod('GET');
HttpWebRequestMgt.SetReturnType('application/json');
HttpWebRequestMgt.SetContentType('application/json');
HttpWebRequestMgt.AddHeader('Authorization',FORMAT(EInvIntegrationSetup."Bearer Token"));
ServicePMgr.Expect100Continue:=TRUE;
ServicePMgr.SecurityProtocol(SecurityProtocal.Tls12);
TempBlob2.INIT;
TempBlob2.Blob.CREATEINSTREAM(ResponseInStream_L);
IF HttpWebRequestMgt.GetResponse(ResponseInStream_L,HttpStatusCode_L,ResponseHeaders_L) THEN BEGIN
ResponseInStream_L.READ(ResponseText2);
//MESSAGE('%1',ResponseText2);
Json2 := ResponseText2;
ReadJSon(Json2,DataExch);
IF GetJsonNodeValue('status.message') = 'Error' THEN
ERROR(GetJsonNodeValue('datalist..error.message.message'));
InsertResponse_New(Rec."No.",1,'');
COMMIT;
IF GetJsonNodeValue('datalist..einv.Irn') <> '' THEN
MESSAGE(Text50000,Rec."No.")
ELSE
//ERROR('E-Invoice not generated.');
MESSAGE('E-Invoice Request No. Updated !!');
END;
END ELSE
ERROR('E-Invoice not generated.');
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions