c# - Sending SignalR Broadcasts that is running within ASP.NET MVC Application from a Windows Service on the same server -


i have asp.net website uses signalr hubs send messages website users.

i have code calls hubs within business layer , use dependency injection inject instances of hubs asp.net application business layer.

the problem have come against when i've come use business layer within windows service, don't know how instance of hubs.

is possible 'hook' existing signalr hubs server, running within asp.net application , send broadcasts windows service?

i realise can connect client within windows service using following code, wrong way around, want send broadcasts from server...

// code enables client connection var connection = new hubconnection("http://localhost:3537/"); ihubproxy myhub = connection.createhubproxy("notificationhub");  connection.start().wait();   myhub.invoke("setnotificationcount", "5"); 

your hubs hosted in asp.net application. no, there no way can broadcast directly windows service...without using scaleout feature of signalr...

solution 1 (without using scaleout - preferred):

windows service connects hub running inside aps.net app (hub1) client , calls special hub method broadcasts message clients. ofc such method can abused normal (browser) clients. eliminate this, can create hub (hub2) in asp.net app, place method here , use globalhost.connectionmanager.gethubcontext<hub1>() broadcast clients connected hub1. hub2 can protected by authorization windows service can use it. using di container , injecting hubs business logic, should easy define common interface (inotificationservice) , create 2 different implementations - first used inside asp.net app (using hub1 actual notification), second used inside windows service , use hub2 pass notification asp.net app. bl point of view, same thing...

ofc win service -> asp.net communication, can use other communication technology such mvc or webapi (as @pseudonym suggested), not signalr

solution 2

if not solution reason, there idea. think signalr scaleout feature can (mis)used here. host hub1 both inside asp.net and windows service (with different url , port!). though clients connect directly asp.net app, code running inside windows service still able broadcast messages them (messages passed scaleout message bus, asp.net app, clients).

things more complicated using scaleout (need sql server\redis or other signalr backplane + latency etc etc) , want lockout windows service hubs clients cannot connect directly , run hub1 methods (i'm not sure how - 1 idea use hub implementation same name (hubnameattribute) , empty methods + authorization no 1 can connect it). anyway more trouble , should have damn reason go route...


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -