Last post Aug 15, 2014 11:53 AM by derricklau
Jun 13, 2014 12:05 PM|steven.mcneese|LINK
So, we currently have a mobile application that polls the database for assignments/changes for information assigned to a specific device. I am looking at using SignalR to either Push a notification to the device that changes exist and need to be fetched
from the database or actually pushing the changed/added data through the SignalR connection. This will eliminate the constant polling being done by hudreds of mobile devices looking for new/updated data.
When assignments are made/updated, a web service is used to actually update the database. I am trying to figure out the best way for the SignalR server to know that there are additions/changes for a specific mobile device so it can fetch them from the database
and send them to the appropriate conneciton on the hub. I could simply have the server polling the database for additions/changes to data for all devices connected, but that seems like I am just moving the polling from the client to the server.
Since the web methods being called int he web service to add/update data assigned to a specific mobile device, would there be another way for that same web method to trigger the SignalR server to get that specific data from the database (based on key) and
then send it to the connected mobile device. Since the web service is not a persisted connection, I don't think it could hold a connection to the SignalR server as a client.
Can anybody offer a suggestion on how to trigger the SignalR server to perform some action like read specific data from a database and send to the associated client in the hub?
Jun 16, 2014 10:42 AM|steven.mcneese|LINK
No ideas, concepts, recommended approaches. Any input would be appreciated.
Jun 26, 2014 07:53 PM|CoderX|LINK
Couple tips for you here.
1. If it is the mobile device itself calling the web-service to update, then just make that a hub method instead of a web-service, then reply with the response. I'm guessing that is not the case though, so...
2. Have each mobile device register with the signalR hub under a unique signalR group name that keys to that device. Then when data is changed via the web-service send a message from the web-service through your hub to that group.
3. To send a message out on your hub from other code (like your web-service), you'll need to get the context for it, then send your message (like this):
var statsContext = GlobalHost.ConnectionManager.GetHubContext<StatsHub>();
statsContext.Clients.Group("Dashboard").setNotification("Placing in " + queueName + " queue", call.PhoneNumber);
4. Another thing you could do is store the SignalR connection Id for each device when it connects, then use that to directly send a message through a hub. Just have to make sure you update the connection Id when necessary.
Hope that gives you some ideas to pursue. I've used all these techniques, and they all work. YMMV.
Aug 14, 2014 09:34 PM|Ruchira|LINK
You can use SqlDependency with the SignalR.
Please 'Mark as Answer' if this post helps you
Aug 15, 2014 11:53 AM|derricklau|LINK
If the SignalR server/hub is in the same web application as your web service, try this:
IHubContext yourSignalRHub = GlobalHost.ConnectionManager.GetHubContext<YourSignalRHubType>();