简体   繁体   English

SignalR客户端错误:在收到调用结果之前,连接开始重新连接

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

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. 我将使用完整的asp.net SignalR 2.3.0.0客户端和服务器(而不是.net核心Signalr版本)作为问题的开头。

javascript client-side code javascript客户端代码

 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(); 在服务器端,我在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" 如果我花时间通过此服务器端代码,则浏览器中的失败回调将触发,err =“在收到调用结果之前,连接已开始重新连接”

Q1. 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? 我该如何扩展客户端超时,以便JS调用在失败之前等待更长的时间(或无限期),这可能吗?

Q2. 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? 一旦断开连接,我的理解是服务器端方法正在执行的操作仍然可以正常进行...但是客户端不会知道。.在这种情况下,通常如何工作? (ie notify the client of the server-side method result?) (即通知客户端服务器端方法结果?)

Here's what I do... JS Client: 这是我的工作... JS客户端:

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. 您可以在“捕获”中添加对JS客户端函数的调用,以调用并通知结果(如果失败)。 Something like: await Clients.Caller.errorMessage("There was an error processing your request."); 像这样: 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. 注意-我在这里使用Clients.Caller,因为我假设您只想将错误返回给请求者。 Same for your result, have a method to call that returns to the caller. 与您的结果相同,有一种返回到调用方的调用方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM