SignalR自托管的Windows服务,听消息 [英] SignalR self hosted windows service, listening for messages

查看:235
本文介绍了SignalR自托管的Windows服务,听消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立一个Windows服务是自托管的SignalR



我走过教程,如的 signalR自主机上的ASP.Net



我注意到,,至少现在看来,他们正在根据各地广播消息,并且似乎无法找到解决倾听任何东西。



我需要。听从服务,以及广播中的消息



我们已经有了我们的背板设置 - 这是该网站使用的是同一



在一个网站,我可以加入一个组,通过Javascript。我如何加入一个自托管SignalR服务组。



在一个网站注册我在轮毂上的回调。我如何注册相同的回调在自托管服务



一些示例代码,我在的地方,注册和启动SignalR是:



  GlobalHost.DependencyResolver.UseSqlServer(Settings.Default.ISDBContext); 
app.Map(/ signalr,地图= GT;
{
map.UseCors(CorsOptions.AllowAll);
HubConfiguration hubConfig =新HubConfiguration()
{
EnableDetailedErrors = TRUE,
EnableJSONP = TRUE,
};

map.RunSignalR(hubConfig);

});



然后,我开始我的web应用程序是这样的:



SignalR = WebApp.Start<启动>(选件);



选项的网址就是我注册。启动是包含上述signalR映射启动类。



在这里有点失落,因为我以前没有


内置自托管服务< DIV CLASS =h2_lin>解决方案

在一般SignalR提供带它可以邮件推送到客户端,而他们请求更新受益的实时通信环境(您已经阅读了介绍,所以能有这样的)。无论您是从服务中启动你的自我主机不应该有所作为



这是我从您的方案明白:你需要消耗从自我消息-hosted服务。我想你可能只需要一个暗示,的 SignalR桌面客户端的。我想您的应用程序/服务应该启动了该服务,然后作为一个客户端服务本身。这将是最干净的方法



由于JavaScript的客户它充当服务的消费者具有相同的功能:



  HubConnection康恩=新HubConnection(http://192.168.1.1:8080); 
IHubProxy枢纽= conn.CreateHubProxy(ChatHub);

//从枢纽打电话给客户
hub.On<字符串,字符串>(方法addMessage(姓名,消息)=>
{
/ /处理来电数据更新
});

和反之亦然从桌面客户端的中心:

 等待hub.Invoke<字符串,字符串>(发送,名称,消息); 

要使用组,逻辑必须集线器中定义。文档使用群组工作给出了一个可以理解的概述。


I'm attempting to build a windows service that's self-hosting SignalR.

I have read through tutorials such as SignalR Self-Host on ASP.Net

I'm noticing that, least it seems, that they're based around broadcasting messages, and can't seem to find anything around listening.

I need to listen to messages from within the service, as well as broadcast.

We already have our backplane setup - it's the same one that the site uses.

In a web site I can join a group, via Javascript. How do I join a group in a self-hosted SignalR service.

In a web site I register a callback on a hub. How do i register the same callback in a self-hosted service?

some example code that I have in place, for registering and starting SignalR is:

GlobalHost.DependencyResolver.UseSqlServer(Settings.Default.ISDBContext);
        app.Map("/signalr", map =>
        {
            map.UseCors(CorsOptions.AllowAll);
            HubConfiguration hubConfig = new HubConfiguration()
            {
                EnableDetailedErrors = true,
                EnableJSONP = true,
            };

            map.RunSignalR(hubConfig);

        });

I then start my webApp like this:

SignalR = WebApp.Start<Startup>(options);

options are the url's i'm registering. Startup is the startup class containing the signalR mapping above.

Little lost here as I haven't built a self-hosting service before

解决方案

In general SignalR offers a real-time messaging environment with the benefit that it can push messages to clients without them requesting the update (you've read the intro, so enough for that). Whether you start your self-host from within a service shouldn't make a difference.

From what I understand from your scenario: You need to consume the messages from the self-hosted service. I think you might only need a hint to the SignalR Desktop Client. I think your app/service should start off the service and then act as a client to the service itself. This would be the cleanest approach.

As the javascript client it acts as a consumer of the service with the same capabilities:

HubConnection conn = new HubConnection("http://192.168.1.1:8080");
IHubProxy hub = conn.CreateHubProxy("ChatHub");

// call from hub to client
hub.On<string, string>("addMessage", (name, message) =>
{
     // Handle incoming data update
});

and vice versa from the desktop client to the hub:

await hub.Invoke<string, string>("Send", name, message);

To work with groups, the logic needs to be defined within your hub. The documentation Working with groups gives an understandable overview.

这篇关于SignalR自托管的Windows服务,听消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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