microsoft / Dynamics-AX-Integration

Dynamics AX Integration samples and demos.
287 stars 356 forks source link

Getting error saying "The underlying connection was closed: An unexpected error occurred on a send." #45

Open prdpmv opened 6 years ago

prdpmv commented 6 years ago

I am getting error saying "The underlying connection was closed: An unexpected error occurred on a send." when I execute ODataConsoleApplication project. Getting error on below line when I tried to get individual record. foreach (var legalEntity in d365.LegalEntities.AsEnumerable())

Getting same error on all methods on QueryExamples class. Please let me know how to fix same. image

tek9iner commented 6 years ago

I was getting the same error in my project when I switched it to point to our production environment. What solved it for me was changing the target framework in my solution to .net 4.6 and then it started working after that.

pfk74 commented 6 years ago

Right now I'm trying to switch to .NET 4.6.2 but I'm not convinced that .NET framework version is the problem or the real solution. I have switched between different dev-env's and get the error as well. It is working fin with .NET4.5.2 in one env but not in the other. If someone knows what is causing this error it would be very nice to know more about it

pfk74 commented 6 years ago

This error is due to differences in TLS between tier1 and tier2(for example) systems. Switching to .NET 4.6+ actually fixes the problem.

RobvanB commented 6 years ago

I've switched to 4.6.1, but I am still having the problem - any ideas what else could be causing this ?

RobvanB commented 6 years ago

Found the solotion. Adding this to the client fixes it: using System.Net; ... //Use Tls1.2 as default transport layer ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

jagadesh77 commented 5 years ago

Hi All - This error was reported in many forums and everyone seems to have lost hopes in finding a solution. Here it is:

1) Add below line in the Main() of oDataConsoleApplication ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

2) As part of the solution on GitHub, you might have registered your Native App (which is the C# solution on GitHub). Now, take the Application (Client) Id of this native application and add it in the Dynamics 365 for operations at System Administration -> Azure Active Directory applications. Make sure the user selected has System admin privileges.

Courtesy: https://codeshare.co.uk/blog/how-to-fix-the-error-authentication-failed-because-the-remote-party-has-closed-the-transport-stream/

Cheers Jag