Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to
handshake
via web socket in c# to a server with Self Signed Certificate and got exception as below:

Exception got as below:
<pre>The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.


I have downloaded the ssl certificate got from server and imported in the client side successfully as per below link:

https://support.quovadisglobal.com/kb/a66/how-do-i-install-a-digital-certificate-onto-windows-7.aspx

Certificate Installed has come in intermediate store on checking. But even after that while trying to communicate getting the same exception:
underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.

What I have tried:

Core code as below:
In the server side it is hosted as https://10.15.1.5/Test.aspx
Connecting to Client as below:
Connect("wss://10.15.1.5/Test.aspx/)
public async Task Connect(string uri)
{



Thread.Sleep(1000);

try
{
txtLog.Text += "Client:Connectivity Process Started under " + MethodInfo.GetCurrentMethod().Name + Environment.NewLine;
webSocket = new ClientWebSocket();

await webSocket.ConnectAsync(new Uri(uri), CancellationToken.None);



}
catch (Exception ex)
{
txtError.Text += "Client:Connectivity Process Failure under " + MethodInfo.GetCurrentMethod().Name + ex.Message.ToString() + Environment.NewLine;
txtError.Text += "Client:Connectivity Process Failure under " + MethodInfo.GetCurrentMethod().Name + ex.InnerException.ToString() + Environment.NewLine;
txtError.Text += "Client:Connectivity Process Failure under " + MethodInfo.GetCurrentMethod().Name + ex.StackTrace.ToString() + Environment.NewLine;

//throw ex;



}
finally
{
if (webSocket != null)
webSocket.Dispose();

}



}
Posted
Updated 23-Jul-18 23:26pm
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900