Resolving error 'The underlying connection was closed: An unexpected error occurred on a send' in NAVISION / Business Central
Introduction:
Today, as I was working with Real-Time Integration with TCI Scribe, I noticed that the integrations which were working prior stopped working.
Although the URL when triggered through the POSTMAN app it works fine.
The error that was received is '{"The underlying connection was closed: An unexpected error occurred on a send."}'
Pre-requisites:
- Microsoft Dynamics NAV / Business Central
- Understanding of .NET Interoperability
- Postman App
- Test Endpoint for API
Procedure:
I have used NAVWebRequest or HTTPWebRequest as .NET interoperability in NAV referring to https://dynamics.is/?p=2739
1. Debugging the issue:In order to make sure that the coding is correctly triggering the URL with POST call and JSON Data Payload, I created an endpoint on Request Bin and the solution seems to be working.
2. Finding the issue and possible solution using C#:
We created a code in C# to test if this could be done through C# Console Application and still got the error.
The connection is force closed. |
After setting the Security Protocol in C# code prior to calling HTTP Request the issue gets resolved.
Variable declaration:
ServicePointManager DotNet System.Net.ServicePointManager.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
SecurityProtocolType DotNet System.Net.SecurityProtocolType.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
Code:
4. Output:
Finally, the integration started working successfully by triggering the URL from NAV.
Finally, the integration started working successfully by triggering the URL from NAV.
Conclusion:
The cause of this issue was that there are security enhancements in API Endpoints and it requires TLS Security Protocol to be set prior to triggering the request.
Special thanks to Subash Mahato for helping me with the C# code to confirm the issue and find its resolution.
Special thanks to Subash Mahato for helping me with the C# code to confirm the issue and find its resolution.
Comments
Post a Comment
Let me know your comments below. I'll try my best to answer your comment