gpt4 book ai didi

asp.net - 使用 SignalR hub 连接到另一个 SignalR hub

转载 作者:行者123 更新时间:2023-12-03 22:00:33 25 4
gpt4 key购买 nike

<分区>

我有一个具有 SignalR 集线器的网站,在这个集线器中,我需要连接到另一个也托管在网站中的 SignalR 集线器。

public FirstHub : Hub, IDisconnect
{

public void FirstMethod()
///Connect to second hub in the second website.
HubConnection hubConnection = new HubConnection("http://localhost:1234");
IHubProxy firstHub = hubConnection.CreateProxy("SecondWebSite.SecondHub");
firstHub.On("secondCallBack", i =>
{
Caller.showMessage("Ok, Website 2 has return message");
});

hubConnection.Start().Wait();
firstHub.Invoke("SecondMethod").ContinueWith(task =>
{
Caller.showMessage(task.Exception.Message);
}, TaskContinuationOptions.OnlyOnFaulted);
}

在第二个网站中我有这个中心:

public class SecondHub : Hub, IDisconnect
{
public void SecondMethod()
{
Caller.callBack("Yes, I got it");
}
}

在第一个网站我有这个javascript代码

var firstHub = $.connection.firstHub;
$.connection.hub.start({ transport: 'auto' }, function () {
alert('connected');
});
$('#TestButton').click(function () {
firstHub.firstMethod();

firstHub.showMessage = function (msg) {
alert(msg);
};

现在,当我打开页面时,我会看到消息(已连接),但是当我按下测试按钮时,我一无所获!而且 fire-bug 控制台没有错误。但有时,我不知道这是怎么发生的,当我进入代码并开始调试时,浏览器显示消息(好的,网站 2 有返回消息)。

我不知道发生了什么!!
这个想法可能吗??我错过了什么吗???

我在输出窗口中得到这些行:

A first chance exception of type 'System.NullReferenceException' occurred in System.Web.dll
Failed to process message: System.NullReferenceException: Object reference not set to an instance of an object.
at System.Web.HttpApplication.ThreadContext.Enter(Boolean setImpersonationContext)
at System.Web.HttpApplication.OnThreadEnterPrivate(Boolean setImpersonationContext)
at System.Web.AspNetSynchronizationContext.CallCallbackPossiblyUnderLock(SendOrPostCallback callback, Object state)
at System.Web.AspNetSynchronizationContext.CallCallback(SendOrPostCallback callback, Object state)
at System.Web.AspNetSynchronizationContext.Post(SendOrPostCallback callback, Object state)
at SignalR.Client.Connection.OnReceived(String message) in D:\TestProjects\SignalR\SignalR.Client\Connection.cs:line 188
at SignalR.Client.Transports.HttpBasedTransport.OnMessage(Connection connection, String response) in D:\TestProjects\SignalR\SignalR.Client\Transports\HttpBasedTransport.cs:line 139

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com