2

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?)

joedotnot
  • 4,810
  • 8
  • 59
  • 91

1 Answers1

0

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.

Frank M
  • 1,379
  • 9
  • 18
  • thanks for the answer but does not really answer my question re timeout issue. As i indicated the error is originating client-side and the connection drops. If there is no connection between client/server or server/client, there is no way for the server to broadcast a message to the client as you have indicated. Client will need to re-establish a new connection.. and the method would most likely have completed by then / or method does not have access to new connection. – joedotnot Jan 16 '19 at 04:49
  • The method I am stating avoids the timeout generally speaking, I have used this for short and long running tasks without encountering the error. Given that a disconnect could occur for many reasons, you could still follow my method and then store your result to provide to the client when they reconnect if they are not connected upon completion. – Frank M Jan 17 '19 at 13:22