【发布时间】:2012-07-31 07:04:45
【问题描述】:
我一直在尝试向所有连接到我的集线器的客户端广播消息,所有桌面浏览器(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
方法 - 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
【问题讨论】:
-
您能否说明您在哪些移动浏览器上看到了这种行为?
-
我有三星 Galaxy S II,所以应该是 Chrome
-
我建议在其他移动浏览器中进行测试,看看它是否仅限于 Chrome。您还可以使用 Android 上 Chrome 的远程调试功能来查看到底发生了什么:developers.google.com/chrome/mobile/docs/debugging
标签: asp.net-mvc knockout.js signalr