SignalR不向客户广播 - (移动浏览器)通过wifi连接

时间:2012-07-31 07:04:46

标签: asp.net-mvc knockout.js signalr

我一直在尝试向连接到我的集线器的所有客户端广播消息,所有桌面浏览器(IE 9,Chrome 20.x)都会收到除通过WiFi连接的移动浏览器之外的消息。我在IIS7中部署了应用程序,并使用在LAN中访问它。

所以我拥有的服务器代码如下 -

[HubName("notifications")]
public class Notifications : Hub
{
    try
    {
      using (var context = new xxxEntities())
        {
         // EF code that post the record to the database
             Clients.taskAdded(message);
             return true;
        }
     }
     catch (Exception ex)
     {
        Caller.reportError("Unable to create notification message. Make sure title length is between 10 and 140");
        return false;
      }

客户端代码 -

//Handlers for our Hub callbacks  
//Invoked from our TaskHub.cs  
this.hub.taskAdded = function (t) {
messages.push(new notificationViewModel(t.Id, t.Message, t.User, t.Notified, self));
//if (guid != test.guid) //notify all clients except the caller
};

这一切都适用于桌面浏览器,我使用knockout.js来刷新与HTML元素绑定的数据模型(例如列表)。当任务添加到数据库中时,除移动设备外,所有桌面浏览器客户端都刷新。

所以你有任何线索为什么移动浏览器不会得到通知?

更新 - 我在IE 9中也有同样的问题,从IE的开发者工具中复制了堆栈

它使用Long Polling传输,我相信IE不支持Web套接字,因此signalR交换机传输到“Long Polling”

以下是每2秒后尝试的网址

网址 - /m.Notifications/signalr/reconnect?transport=longPolling&connectionId=311eed98-4e1d-4a0c-a012-2a41b20eded0&connectionData=%5B%7B%22name%22%3A%22notifications%22%7D%5D& ; MESSAGEID = 18&安培; TID = 7

方法 - GET 结果 - 500(Http响应代码) 启动器 - JS库XMLHttpRequest

对象引用未设置为对象的实例。

堆栈追踪:

[NullReferenceException: Object reference not set to an instance of an object.]
System.Web.HttpContext.GetWebSocketInitStatus() +251
System.Web.HttpContextWrapper.get_IsWebSocketRequest() +46
SignalR.Hosting.AspNet.AspNetResponse.get_IsClientConnected() +48
SignalR.Transports.TransportHeartBeat.AddConnection(ITrackingConnection connection) +280
SignalR.Transports.LongPollingTransport.ProcessReceiveRequest(ITransportConnection connection, Action postReceive) +38
SignalR.TaskAsyncHelper.Interleave(Func`3 before, Func`1 after, T arg, TaskCompletionSource`1 tcs) +181
SignalR.Transports.LongPollingTransport.ProcessRequest(ITransportConnection connection) +295
SignalR.PersistentConnection.ProcessRequestAsync(HostContext context) +892
SignalR.Hosting.AspNet.AspNetHandler.ProcessRequestAsync(HttpContextBase context) +866
System.Web.TaskAsyncHelper.BeginTask(Func`1 taskFunc, AsyncCallback callback, Object state) +50     System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +12519412
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288

1 个答案:

答案 0 :(得分:0)

新版本运行良好,我从https://github.com/SignalR/SignalR/下载了最新资源 我看到有长轮询运输的修复,假设这个问题也已经解决了

我会仔细审查自0.5.2以来修复的内容。

一个观察 - 在网络选项卡下的IE 9开发人员工具中,您将看到一个正在运行的请求(主要是最后一个请求)状态为“待定”,当您收到状态时,状态立即发生了变化通知/或者您向服务器发送内容,对于不支持Web套接字的浏览器,这应该是长轮询技术。