web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :

Resolving error 'The underlying connection was closed: An unexpected error occurred on a send' in NAVISION / Business Central

Olister Rumao Profile Picture Olister Rumao 3,967

 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.
Request Bin

Also, when triggering the URL through Postman, the response is correctly generated.
Postman Trigger

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.
Request processed successfully


3. NAV equivalent code:
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:
Adding Service Point Manager Security Protocol


4. Output:
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.

Comments

*This post is locked for comments