SignalR client-side error: Connection started reconnecting before invocation result was received

Viewed 1029

I'll preface the question with I am using the full asp.net SignalR 2.3.0.0 client and server, NOT the .net core signalr version.

javascript client-side code

 var pxyHub = $.connection.myHub; 

 $.connection.hub.start();

 pxyHub.server.myServerSideMethod(val1, val2)
    .done( (rntVal) => {
        //do stuff on success...
        })
    .fail( (err) => {
        //do stuff on error...
        })

On the server-side i put a breakpoint inside the myServerSideMethod(); If i take my time stepping thru this server-side code, the fail callback in the Browser will fire, err= "Connection started reconnecting before invocation result was received"

Q1. How can I extend the timeout client-side, so that the JS call waits for a longer period (or indefinitely) before failing, is it possible?

Q2. Once the connection is broken, it is my understanding whatever the server-side method was doing may still continue normally... but the client won't know about it.. How does one normally work around this scenario? (i.e. notify the client of the server-side method result?)

1 Answers

Here's what I do... JS Client:

return myHubProxy.server.getUsers();

In my Hub I have:

public async Task GetUsers()
{
    try{
         //do stuff to get list of users from database
       }
    catch(Exception ex)
    {

    }
    await Clients.All.usersonline((new JavaScriptSerializer()).Serialize(userlist));
}

You could in the "catch" add a call to a JS client side function to call and inform of results if it failed. Something like: await Clients.Caller.errorMessage("There was an error processing your request."); Note - I am using Clients.Caller here as I am assuming you would only want to return the error to the requester. Same for your result, have a method to call that returns to the caller.

Related