Signalr 为什么我的网页失去了接收信号器消息的能力
基本上我有3个应用程序。我的集线器的web应用程序、Nservicebus和Signal自托管服务器。我目前正在使用信号器版本。4。基本上,web应用程序在页面加载时启动与自托管服务器的连接。用户执行一个操作,通过服务总线发送命令。然后,服务总线连接到信号服务器以通知所有web客户端 我的网页:Signalr 为什么我的网页失去了接收信号器消息的能力,signalr,Signalr,基本上我有3个应用程序。我的集线器的web应用程序、Nservicebus和Signal自托管服务器。我目前正在使用信号器版本。4。基本上,web应用程序在页面加载时启动与自托管服务器的连接。用户执行一个操作,通过服务总线发送命令。然后,服务总线连接到信号服务器以通知所有web客户端 我的网页: <script src="http://localhost:8081/test/signalr/hubs" type="text/javascript"></script> &l
<script src="http://localhost:8081/test/signalr/hubs" type="text/javascript"></script>
<script>
jQuery.support.cors = true;
var myHub;
$.connection.hub.url = 'http://localhost:8081/test/signalr/hubs';
$(function () {
myHub = $.connection.userAccountHub;
myHub.ChangeNameUpdated = function (connId) {
alert("recieved signalr message");
};
$.connection.hub.start().done(function() {
var myClientId = $.connection.hub.id;
setCookie("srconnectionid", myClientId);
});
});
</script>
static void Main(string[] args)
{
Debug.Listeners.Add(new ConsoleTraceListener());
Debug.AutoFlush = true;
string url = "http://localhost:8081/test/";
var server = new Server(url);
server.EnableHubs();
server.Start();
Console.WriteLine("Server running on {0}", url);
while (true)
strong text{
ConsoleKeyInfo ki = Console.ReadKey(true);
if (ki.Key == ConsoleKey.X)
{
break;
}
}
}
我的信号服务器项目中的我的集线器
public class UserAccountHub : Hub
{
public void UsersNameChanged(string passedThroughConnectionId)
{
Clients.ChangeNameUpdated(passedThroughConnectionId);
}
}
我的N服务总线呼叫
//connect to signalRServer
var connection = new HubConnection("http://localhost:8081/test/signalr/hubs");
IHubProxy myHub = connection.CreateProxy("SignalRServer.Hubs.UserAccountHub");
//Credentials are inherited from the application
connection.Credentials = CredentialCache.DefaultNetworkCredentials;
var test = message.GetHeader("signalrConnectionId");
connection.Start().Wait();
myHub.Invoke("UsersNameChanged", message.GetHeader("signalrConnectionId")).ContinueWith(task =>
{
//for debuging purposes
if (task.IsFaulted)
{
Console.WriteLine(
"An error occurred during the method call {0}",
task.Exception.GetBaseException());
}
else
{
Console.WriteLine("Successfully called MethodOnServer");
}
});
我打开了两个浏览器。我在第二个浏览器上启动该过程,只有第一个浏览器接收通知。第二个浏览器没有
当我运行fiddler时,我也没有看到任何突出的问题
是否有更好的实现方法,或者我遗漏了什么?好的!大卫的评论让我走上了正确的方向。也注意到这个更新了,以前没注意到 1.)更新至第5版 2.)在javascript中将我的连接信息修改为
$.connection.hub.url = 'http://localhost:8081/test/signalr';
$.connection.hub.start({ transport: 'longPolling', xdomain: true }).done(function () {
//alert("staring hub connection: " + $.connection.hub.id);
setCookie("srconnectionid", $.connection.hub.id);
});
3.)我必须更改轮毂连接
var connection = new HubConnection("http://localhost:8081/test/");
4.)我必须更改IHubProxy
IHubProxy myHub = connection.CreateProxy("UserAccountHub");
这些都有用吗<代码>var连接=新HUB连接(“http://localhost:8081/test/signalr/hubs");代码>以上行不正确。创建到中心url的连接,如下所示:
var connection=new HubConnection(“http://localhost:8081/test/");代码>与javascript中心url相同,它应该是:$.connection.hub.url='';它“有时”起作用,这让我觉得我正确地完成了连接部分。如果我只使用一个浏览器,一切都正常(第一次),如果我尝试执行第二个操作,它将停止接收通知。但是,如果我从头开始刷新页面,它将收到1个通知,然后不再收到任何通知。在检查了fiddler的一个不同的项目后,我看到了一个不同。此解决方案在收到第一个通知后停止长时间轮询。我将使用您指定的连接进行签出。这很奇怪。因为它看起来根本不应该起作用。谢谢大卫,你的评论让我走上了正确的方向。我升级到.5,然后仔细研究了如何处理连接字符串。