Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

URL for Client to Connect to SignalR Server #5122


User avatar
0
pankajmathur created

I have an application(Let's call it server application) that is built using ABP Framework and has the SignalR implemented. My Startup Class has the following code.

app.UseSignalR(routes => { routes.MapHub<iVend365Hub>("/signalr"); });

I have another WebApplication (Let's call it client application) that is built on normal ASP.Net Core framework and NOT the ABP framework.

Now when my client application needs to connect to my server application via signalR, what would the URL of src attribute of script tag that the client application should inject. I am talking about following script tag that the client application should inject

<script src="<WHAT SHOULD BE THE URL HERE>" type="text/javascript"></script>

I tried browsing the URL <a class="postlink" href="http://localhost:62114/signalr">http://localhost:62114/signalr</a> but it says "Connection ID required"......

Please help

Regards, Mahendra


10 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team
    <script src="http://localhost:62114/lib/signalr-client/signalr.min.js"></script>
    <script>
        var connection = new signalR.HubConnection('http://localhost:62114/signalr', { transport: signalR.TransportType.WebSockets });
        connection.start();
    </script>
    

    For advanced usage, see how ABP implements abp.signalr-client.js.

    You may need to enable CORS.

  • User Avatar
    0
    pankajmathur created

    Using your suggestion....I am able to successfully connect my client application with Server Application and also receive the message from server....Thanks for this...

    But if my client application is a classic windows desktop application (instead of web application), then I am unable to connect to the server...

    See the code below

    HubConnection hubConnection; IHubProxy hubProxy;

    hubConnection = new HubConnection("http://localhost:62114/signalr"); hubProxy = hubConnection.CreateHubProxy("iVend365Hub"); hubProxy.On<string>("getMessage", (message) => MessageBox.Show(message)); hubConnection.Start().Wait();

    In the last line of above code "hubConnection.Start().Wait();", it throws the following error..

    System.AggregateException occurred HResult=0x80131500 Message=One or more errors occurred. Source=mscorlib StackTrace: at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at System.Threading.Tasks.Task.Wait() at WinFormsApp1.Form1..ctor() in D:\MNJ\R&D\SignalRDemo\WinFormsApp1\Form1.cs:line 25 at WinFormsApp1.Program.Main() in D:\MNJ\R&D\SignalRDemo\WinFormsApp1\Program.cs:line 19

    Inner Exception 1: JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 2, position 1.

    What am I missing...Please advise..

    Regards, Mahendra

  • User Avatar
    0
    aaron created
    Support Team

    Are you using Microsoft.AspNetCore.SignalR.Client 1.0.0-preview1-28189?

  • User Avatar
    0
    pankajmathur created

    I am using following nuget in Windows App.

    Microsoft.AspNet.SignalR.Client 2.2.2

  • User Avatar
    0
    aaron created
    Support Team

    That's incompatible.

  • User Avatar
    0
    pankajmathur created

    Do you recommend try using Microsoft.AspNetCore.SignalR.Client 1.0.0-preview1-28189

  • User Avatar
    0
    aaron created
    Support Team

    Yes.

  • User Avatar
    0
    pankajmathur created

    Hi Aaron,

    If my client application is WEB then it is successfully connect to my SignalR Server. Here is the Code of client

    <script src="Scripts/jquery-1.6.4.js"></script> <script src="Scripts/jquery.signalR-2.2.2.js"></script>

    &lt;script src=&quot;http://localhost:62114/lib/signalr-client/signalr.min.js&quot;&gt;&lt;/script&gt;
    &lt;script&gt;
        debugger;
        var connection = new signalR.HubConnection('http://localhost:62114/signalr', { transport: signalR.TransportType.WebSockets });
        connection.start();
        connection.on("getMessage", function (message) {
            alert(message);
        });
    &lt;/script&gt;
    

    But if my client application is .Net Core Console application, I am unable to connect. Here is my code. var hubConnection = new HubConnectionBuilder() .WithUrl("http://localhost:62114/signalr", HttpTransportType.WebSockets) .Build();

                hubConnection.On&lt;string&gt;("getMessage", (message) => Console.WriteLine(message));
                hubConnection.StartAsync().Wait();
    

    The error it says is Unable to connect to the server with any of the available transports...

    I am using

    What is wrong here? Please advise...

  • User Avatar
    0
    pankajmathur created

    Hi Aaron,

    Finally I got my mistake...The ABP 3.6.1 is using SignalR Preview1 and My Console App was using signalR RC1 and thats why my console app was not connecting the the server. The moment I took SignalR Preview1 (As suggested by you), it starts connecting the server..

    Thanks again for your help....

    Regards, Mahendra

  • User Avatar
    0
    aaron created
    Support Team

    That's great :)