Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am having issue while trying to connect via web socket to a url with wss protocol. The hosted url with http works fine when i try to consume from client with ws protocol. But with https i get below exception. I created a self signed certificate in IIS and was able to start server. But while trying to connect I am getting below exception.


Exception is as below:
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.


What I have tried:

Core Code is as below:
Server
HttpListener httpListener = new HttpListener();
               httpListener.Prefixes.Add(httpListenerPrefix);
               httpListener.Start();

Client
public async Task Connect(string uri)
     {




         //NeSTCommonClass.WriteTextFile(LogPath + Logfilename, "Client:Handshake Connectivity  Process Sending  Starts", true);
         Thread.Sleep(1000); //wait for a sec, so server starts and ready to accept connection..

         // ClientWebSocket webSocket = null;
         try
         {
             webSocket = new ClientWebSocket();
             await webSocket.ConnectAsync(new Uri(uri), CancellationToken.None);
            //NeSTCommonClass.WriteTextFile(LogPath + Logfilename, "Client:Handshake Connectivity  Process Sending  Ends", true);
             //await Task.WhenAll(Receive(webSocket));



         }
         catch (Exception ex)
         {


             txtError.Text += "Client:HandShake Connectivity Process Failed: "+ ex.Message.ToString()+" "+ MethodInfo.GetCurrentMethod().Name  + Environment.NewLine;
             txtError.Text += "Client:HandShake Connectivity Process Failed: " + ex.InnerException.ToString() + " " + MethodInfo.GetCurrentMethod().Name + Environment.NewLine;
             txtError.Text += "Client:HandShake Connectivity Process Failed: " + ex.StackTrace.ToString() + " " + MethodInfo.GetCurrentMethod().Name + Environment.NewLine;
             //NeSTCommonClass.WriteTextFile(LogPath + Logfilename, "Client:HandShake Connectivity Process Failed: " + ex.Message.ToString() + "", true);


         }
         finally
         {
             if (webSocket != null)
                 webSocket.Dispose();
             //Console.WriteLine();
             //Console.WriteLine("WebSocket closed.");
         }
        // NeSTCommonClass.WriteTextFile(LogPath + Logfilename, "Client:Handshake Connectivity  Process Sending from Client Level Process Ends", true);
     }
Posted
Comments
Jochen Arndt 10-Jul-18 7:41am    
Enter "The remote certificate is invalid according to the validation procedure" into the input field of your favorite search engine.

Also, why do have deleted your previous question?
Was it solved by my comment?

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