Error when trying to connect to the API - recent API changes

Hi there,

I have a project developed in C# that uses WebSocket to connect, it was working properly but it stopped working, maybe by the recent changes in the API, now I'm getting the following error:

Message: A call to SSPI failed, see inner exception.
InnerException = {"The function requested is not supported"}

Stacktrace
at System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult lazyResult)
at System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult result)
at System.Net.Security.SslStream.EndAuthenticateAsClient(IAsyncResult asyncResult)
at SuperSocket.ClientEngine.SslStreamTcpSession.OnAuthenticated(IAsyncResult result)

Actions I tried that didn't work for me:
1) Using a package named WebScoket4Net: I tried changing the Security Protocol directly to set TLS1.2 | SSL3
2) I removed the package and I used System.Net.WebSocket, same problem | same playing with the protocols and so on... didn't work...
3) I tried copying and pasting the C# Code Example that provides the website Binary.Com developers : link: https://developers.binary.com/demos/..... the message I got was "One or more error occurred"
4) I Tried updating the framework version to 4.6+ .. a solution posted in this community, the post said ("...see this stack overflow question and answer https://stackoverflow.com/questions/42817334/ssl-tls-1-2-channel-creation-vb-net-https-webrequest")... same result.

I'm getting out of ideas, please help!!!
Thank you.

Comments

  • @robaez2 In your original code did you try adding this ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; before you make the connection?

  • Hi @michael_mueller, that line was not originally in my code, however, I'm pretty sure I tested before when looking for solutions, I just tested again now but yet I'm getting the same result:

    Message: A call to SSPI failed, see inner exception.
    InnerException = {"The function requested is not supported"}

    I'm using WebScoket4Net 0.15.2 (Latest version) from Visual Studio/NuGet package
    NuGet Package Project URL: https://archive.codeplex.com/?p=websocket4net

    I'd say that maybe is the package itself but the thing is I have tested other options unsuccessfully.

  • I just tested another Package named WatsonWebsocket it can be found in Visual Studio/ NuGet Packages, and it works well.

    It looks like the old package (WebScoket4Net) has some issues when implementing TLS1.2.

    For the community:
    Other solutions out there may work as well, but just want to add that this one worked just fine for me.
    NuGet Project URL: https://github.com/jchristn/WatsonWebsocket

    by the way, there's a project example where the user can make some tests before implementing it.

    Hope this may help others.

  • @robaez2 can you share some more information or example with the way you are using WatsonWebsocket, please. I was using WebSocket4Net and it is no more working. So I am migrating to WatsonWebsocket.
    I have implemented WatsonWebsocket exactly the same way as I used to connect with WebSocket4Net. But with WatsonWebsocket it is getting disconnected as soon as I try to start().

  • @kashyap33 said:
    @robaez2 can you share some more information or example with the way you are using WatsonWebsocket, please. I was using WebSocket4Net and it is no more working. So I am migrating to WatsonWebsocket.
    I have implemented WatsonWebsocket exactly the same way as I used to connect with WebSocket4Net. But with WatsonWebsocket it is getting disconnected as soon as I try to start().

    Please help, I don't even want to connect. What am I doing wrong?

  • did you replace app_id=xxxx with your app_id?

  • @michael_mueller said:
    did you replace app_id=xxxx with your app_id?

    Yes, of course

  • I solved the problem like this: I explicitly specified ssl 1.2, I don't know if it's correct or not, but it works. Possible so:

    private enum SslProtocolsHack
    {
    // Tls = 192,
    // Tls11 = 768,
    Tls12 = 3072
    }
    ws.OnClose += (sender, e) =>
    {
    var sslProtocolHack = (System.Security.Authentication.SslProtocols)(SslProtocolsHack.Tls12);
    // | SslProtocolsHack.Tls11 | SslProtocolsHack.Tls);
    //TlsHandshakeFailure
    if (e.Code == 1015 && ws.SslConfiguration.EnabledSslProtocols != sslProtocolHack)
    {
    ws.SslConfiguration.EnabledSslProtocols = sslProtocolHack;
    ws.Connect();
    }
    };

    But I did it in Main:

    static void Main(string[] args)
    {

            using (var ws = new WebSocket("wss://ws.binaryws.com/websockets/v3?app_id=XXXX"))
            {
    
    
    
                var sslProtocolHack = (System.Security.Authentication.SslProtocols)(sssl.SslProtocolsHack.Tls12);
                ws.OnMessage += (sender, e) =>
                    Console.WriteLine("Laputa says: " + e.Data);
                ws.SslConfiguration.EnabledSslProtocols = sslProtocolHack;
                ws.Connect();
                Thread.Sleep(5000);
                ws.Send("{\"authorize\": \"XXXXXXXXXXXXXX\"}");
                Console.ReadKey(true);
            }
     }
    

    I put the SL enumeration in a separate class.Used this library https://github.com/sta/websocket-sharp, I haven't tried Watsonwebsocket, but I think It should work too.

  • It is still not working for me. here is my code
    using (var ws = new WebSocket("wss://ws.binaryws.com/websockets/v3?app_id=XXXX"))
    {
    //var sslProtocolHack = (System.Security.Authentication.SslProtocols)(sssl.SslProtocolsHack.Tls12);
    ws.OnMessage += (sender, e) =>
    Console.WriteLine("Laputa says: " + e.Data);
    ws.SslConfiguration.EnabledSslProtocols = System.Security.Authentication.SslProtocols.Tls12;
    ws.Connect();
    Thread.Sleep(5000);
    ws.Send("{\"authorize\": \"XXXXXXXXXXXXXX\"}");
    Console.ReadKey(true);
    }

  • receiving this message "08/25/2020 12:24:15 AM|Fatal|WebSocket.connect:0|An error has occurred during a TLS handshake."

  • Please suggest

Sign In or Register to comment.