SignalR MVC SignalR Server和Windows服务SIgnalR客户端之间的 [英] SignalR Between MVC SignalR Server and Windows Service SIgnalR Client

查看:199
本文介绍了SignalR MVC SignalR Server和Windows服务SIgnalR客户端之间的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从这里问,我可以在一个普通的老的Windows服务有SignalR知道。我想了Windows服务作为SignalR客户端和ASP.NET MVC SignalR服务器之间的通信。我用这个集线器指南,它说

I already know from asking here that I can have SignalR in a plain old Windows Service. I want to communicate between that Windows Service as a SignalR Client and a ASP.NET MVC SignalR Server. I used this hubs guide, It said

服务器code,指定网址

Server code that specifies the URL

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

如果我这样做,在那里将消息去了?什么是集线器时,你做新HubConfiguration?

If I do that, where will the messages go? What is the hub when you do new HubConfiguration?

它说我可以连接

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

我要在我的Windows服务器,但如果我发短信给 http://myserver.com/signalr 在服务器上,我怎么得到它呢?什么枢纽?

I'll have that in my Windows Server but if I send text to http://myserver.com/signalr on the server, how do I get it? What hub?

此外哪里最好把这个在​​Windows服务?一个例子是伟大的!

Also where best to put this in the Windows service? An example would be great!

推荐答案

这解决了这个问题。

在客户端(Windows服务):

On the client (Windows Service):

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

        }

这篇关于SignalR MVC SignalR Server和Windows服务SIgnalR客户端之间的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆