1

我一直在尝试向连接到我的集线器的所有客户端广播消息,所有桌面浏览器(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 的开发人员工具中复制了堆栈

它使用长轮询传输,我相信 IE 不支持网络套接字,因此 signalR 将传输切换到“长轮询”

这是它每 2 秒尝试一次的 URL

URL - /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

Method - GET Result - 500 (Http response code) Initiator - 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
4

1 回答 1

0

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

我将进一步审查自 0.5.2 以来修复的内容

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

于 2012-08-01T09:45:29.120 回答