.net - How to broadcast events from Web Api project to MVC app on a different App Pool using SignalR -
my windows server running iis has mvc application in 1 app pool , web api project in another. these projects developed in different solutions. web app communicates web api use rest service. need add signalr hub web api project can broadcast data web app in situations.
how can go doing this? have read in other posts need use sql server backplane i'm not sure necessary since 2 apps on same server. if case though, how web app pick broadcast when hub code not in project?
since using single server, stay away backbone scale out (i.e. sql server message bus, redis etc) until forced scale out multiple servers, in experience signalr scale out can painful multiple reasons.
because have solutions in different app pools, need think of 1 "signalr server" , other "client". pick web api server project , web app client.
in order communicate "server" "client" should treat web app other .net client (i.e. can use console app signalr client). @ start up, or @ other event in web app have register "server"(web api) listening out messages signalr has send. there many great tutorials on over @ asp.net, @ time of writing this link explains how go setting up, have extreamly simplified tutorial below:
1). install microsoft.aspnet.signalr.client nuget
2). register hub , start async connection:
var hubconnection = new hubconnection("http://www.contoso.com/"); ihubproxy stocktickerhubproxy = hubconnection.createhubproxy("stocktickerhub"); stocktickerhubproxy.on<stock>("updatestockprice", stock => console.writeline("stock update {0} new price {1}", stock.symbol, stock.price)); await hubconnection.start();
Comments
Post a Comment