asp.net-mvc - MVC SignalR 服务器和 Windows 服务 SIignalR 客户端之间的 SignalR

标签 asp.net-mvc windows-services signalr

通过询问,我已经知道我可以在普通的旧 Windows 服务中使用 SignalR。我想在作为 SignalR 客户端的 Windows 服务和 ASP.NET MVC SignalR 服务器之间进行通信。我用过this hubs guide ,它说

指定 URL 的服务器代码

app.MapSignalR("/signalr", new HubConfiguration());

如果我这样做,消息会去哪里?当你做新的HubConfiguration时,集线器是什么?

它说我可以连接

NET client code that specifies the URL
 var hubConnection = new HubConnection("http://contoso.com/signalr", useDefaultUrl: false);

我会将其存储在我的 Windows Server 中,但如果我将文本发送到 http://myserver.com/signalr在服务器上,如何获取?什么枢纽?

另外,最好将其放在 Windows 服务中的哪个位置?举个例子就太好了!

最佳答案

这样就解决了问题

在客户端(Windows 服务):

protected override async void OnStart(string[] args)
        {
            eventLog1.WriteEntry("In OnStart");
            try
            {
                var hubConnection = new HubConnection("http://www.savitassa.com/signalr", useDefaultUrl: false);
                IHubProxy alphaProxy = hubConnection.CreateHubProxy("AlphaHub");

                await hubConnection.Start();

                await alphaProxy.Invoke("Hello", "Message from Service");
            }
            catch (Exception ex)
            {
                eventLog1.WriteEntry(ex.Message);
            }
        }

在服务器上:

public class AlphaHub : Hub
    {
        public void Hello(string message)
        {
            // We got the string from the Windows Service 
            // using SignalR. Now need to send to the clients
            Clients.All.addNewMessageToPage(message);

            // Send message to Windows Service

        }

关于asp.net-mvc - MVC SignalR 服务器和 Windows 服务 SIignalR 客户端之间的 SignalR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21613889/

相关文章:

serialization - 尽管有 JsonSerializer 设置,SignalR 仍未序列化 NodaTime 类型

jquery - 缓存的js文件会减慢页面渲染速度吗

asp.net-mvc - 如何删除 mvc 中带有选定选项标签的下拉菜单的模型状态错误?

asp.net-core - 如何更改 Visual Studio 2017 中用于调试的默认浏览器?

function - Cosmos DB 与 Azure 函数和 SignalR 的集成

model-view-controller - 基于角色的通知以及在 MVC 5 中使用 Signalr 的组

c# - 在 signalr 中管理多个浏览器选项卡

asp.net - HttpContext.User.Identity 为空

c# - Windows 服务托管 TCP WCF 服务

.net - 获取 Windows 服务启动类型?