Base solution for your next web application
Open Closed

SignalR with Web Services #11587


User avatar
0
feryat.olcay created

Hi,

We are interested in implementing a ChatHub-like structure within SignalR. Our clients currently utilize Web Services and .Net 4.7.2. However, when attempting to establish a websocket connection similar to ChatHub, we encounter the following error. Could you kindly provide any suggestions or recommendations to resolve this issue?

Error : "Only 'http' and 'https' schemes are allowed. Parameter name: requestUri"

Simple code : HubConnection connection = new HubConnectionBuilder() .WithUrl($"wss://localhost:44301/signalr-data-collector?enc_auth_token={token}") .WithAutomaticReconnect() .Build();


5 Answer(s)
  • User Avatar
    0
    m.aliozkaya created
    Support Team

    Hi @feryat.olcay,

    Have you tried just passing **https **uri?

  • User Avatar
    0
    feryat.olcay created

    Hi,

    Yes, we tried with "https" and it is working with below code block on localhost. But, it is NOT working on IIS Server.

                    ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertificate;
                    var token = await ZenoService.GetTokenAsync();   
                    HubConnection connection = new HubConnectionBuilder()
                   .WithUrl($"{_signalrUrl}?enc_auth_token={token}")
                   .WithAutomaticReconnect()
                   .Build();
    
                    await connection.StartAsync();
                    .
                    .
                    .
    

    static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; }

    Is there any specific control SignalR IIS Server.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @feryat.olcay

    When you use HTTPS, SignalR itseld uses wss if it is supported by the server. What is the problem you are having with HTTPS on the server ? Is there an error message ?

  • User Avatar
    0
    feryat.olcay created

    Hi,

    We got the following error.

    "System.FormatException: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters."

    When we debugged our project, we realized that the token was not valid. First, we got the encrypted token, and then we needed to encode it for the SignalR URL.

    Code :

                    ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertificate;
                    var token = await _zenoApi.GetTokenAsync(true);
                    var tokenEncode = System.Web.HttpUtility.UrlEncode(token);
                    
                    HubConnection connection = new HubConnectionBuilder()
                   .WithUrl($"{_options.ZenoURL}signalr-data-collector?enc_auth_token={tokenEncode}")
                   .WithAutomaticReconnect()
                   .Build();
    
                   await connection.StartAsync();
    
                
    

    It's working now :) Thanks for your feedback.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @feryat.olcay

    Great to hear that :)