Monday, March 3, 2014

Exception - The underlying connection was closed: An unexpected error occurred on a send.

While connecting to an external web service (using WebRequest), you might get the following error

Exception - The underlying connection was closed: An unexpected error occurred on a send.

The inner exception might be  
"Received an unexpected EOF or 0 bytes from the transport stream"

This might get resolved by setting
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;

I think .NET applications use TLS for transport security by default. So when the external server where the web service resides does not support TLS, I would assume, the connection would be tried using SSL3. But in some cases (like it was for me), the connection failed with the above error. It was resolved by forcing SSL3.

No comments:

Post a Comment