Signalr服务器错过了一些调用客户端的方法

时间:2013-10-10 20:23:57

标签: silverlight signalr signalr-hub signalr.client

我在LongPolling中使用SignalR v1.1.3和Silverlight v5。

我在客户端上遇到服务器调用方法的问题。最后一次通话需要很长时间(接近2分钟)或者被忽略

第一种情况:最后一次通话需要2s

public void TestMethod(){
   Clients.Caller.OnTestMethod();
   Clients.Caller.OnTestMethod();
}

第一个电话立即开始,第二个电话立即开始,但需要2分钟才能被客户抓住。

Fiddler输出(第二列显示已用时间):http://i.stack.imgur.com/BFQi4.png

第二种情况:一次通话需要2s,一次是错过

public void TestMethod(){
   Clients.Caller.OnTestMethod();
   Clients.Caller.OnTestMethod();
   Clients.Caller.OnTestMethod();
   Clients.Caller.OnTestMethod();
}

前两个呼叫是“快速”,第三个呼叫是2秒,最后一个呼叫从未发送

Fiddler输出(第二列显示已用时间):http://i.stack.imgur.com/Yj1fw.png

最后一种情况:上次通话需要2s

public void TestMethod(){
   Clients.Caller.OnTestMethod();
   Clients.Caller.OnTestMethod();
   Clients.Caller.OnTestMethod();
   Thread.Sleep(50);
   Clients.Caller.OnTestMethod();
}

在最后一次之前添加睡眠允许完成呼叫。

Fiddler输出(第二列显示已用时间):http://i.stack.imgur.com/O7p0Y.png

客户端上的代码是

await hubProxy.Invoke("TestMethod");

*编辑*

在客户端上我有一个服务,它为服务器上的每个集线器创建一个hubproxy:

    public MyHubConnection()
    {
        _hubConnection = new HubConnection(ApplicationHelpers.GetServerRootUri()) {TraceLevel = TraceLevels.All, TraceWriter = Console.Out};
        _hubConnection.Error += ErrorFns.HandleError;
    }

    public async Task StartAsync()
    {
        var time = DateTime.Now;

        var manager = new EntityManager(); 
        var serverHubs = (List<string>)await manager.InvokeServerMethodAsync("Common.SignalRServices, Common", "GetServerHubs");

        foreach (var serverHub in serverHubs)
        {
            _hubRepository[serverHub] = _hubConnection.CreateHubProxy(serverHub);
        }

        await _hubConnection.Start(new LongPollingTransport());
    }

    public IHubProxy GetHubProxy(string hubName)
    {
        if (!_hubRepository.ContainsKey(hubName))
            throw new Exception(string.Format("No hub named '{0}'", hubName));

        return _hubRepository[hubName];
    }

我不知道发生了什么......任何线索?

1 个答案:

答案 0 :(得分:0)

我们的客户使用SSE传输(https://github.com/SignalR/SignalR/issues/763)存在Silverlight问题。尝试使用longpolling,看看它是否解决了你的问题。