What are the approaches to trigger ASP.NET Website server side push - asp.net

We are implementing Signalr to provide real time updates to browser clients. But we are curretnly stuck as we need to make http server itself (IIS+ASP) detect the changes from database and external services or from any other source without polling?
I believe this should be a common problem with all real time websites (irrespective of what technology is used for server side push SignalR, Comet or WebSync). Please provide what are general approaches used in such situations?

If you can, raise an event in whatever code is updating your database. Use that event to trigger the message publication.
Ready to update database -> Update database
-> Publish to WebSync
If you can't control the code updating your database, use the SqlDependency class. It lets you define a SELECT statement and then notifies you whenever the results of that query change. Use the notification event to trigger the message publication.
Update database -> SqlDependency -> Publish to WebSync

Related

web-dev - Real-time page update from database based on special ID

I'm trying to build a web app that lets a user create a session which generates a unique session ID through which other users can join the session and post messages on a board. However, I am stuck at real-time updates for the specific sessions as I am unaware of technologies that allow me to accomplish this task. I've read about .NET's SignalR as a real-time web app API but so far have not found a way to handle each session separately. I am looking for recommendations and preferably tutorials on how to implement this feature.
The Web API is built in Spring Boot and .NET, so I would prefer APIs/tutorials for these frameworks. Thank you.
Just thinking of the easiest way to do this with minimal strain on the server. I think I would go down the road of storing the session IDs in the db and then use ajax to handle the realtime updates. Ajax can run on a js timing loop that can check a serverside flag which is set once updates are made to the db. Upon finding a set flag the ajax can then pull in the updates or do a page refresh.

Difference between web and desktop applications in database access

i have a bit theoretical question.
When creating web applications, there is difference to desktop applications with working and active connection to database. So im curious if there is some solution, which can provide more desktop-like access to database e.g. transactions on asynchronous requests from client (web browser)?
edit:
So i figured out, that there can be a transaction process of asynchronous request, from client. Is there solution, which can provide it in web apps?
e.g I have assynchronou ajax call, which consist of multiple operations, and i wana to process them as transaction. If everything is okay, operations will be all done. But if one of them fail, just rollback it. Like its in DB. Is it possible?
edit2: maybe im wrong and the issue is not about ajax, but about whole web applications, but i dont think there is a way how to make a asynchronnous request from web client.
Transaction need continuous connection to database. To make it work with web application you need a platform which allow the application to run continuously independent of client request. Java servlet is best fit, php is a no-no. So I asume you will use java servlet.
In java servlet, you can create a db transaction, create an id for it, and then store them in a static variable or in the provided application-wide object, context. Then, return the id to the client.
When the client want to send another request, make it send the id. The application then can locate the transaction variable based on the id. As long as the application doesn't restarted between the two requests, the transaction is still there and active.
Because web application don't know when the user leave the application, you must create a mechanism to check the transactions periodically, and then rollback it if the user leave them for a specified time period.
The database has no knowledge of who is connected outside of authentication.

Meteor: redirect a collection update to a service call

Following the example here I am able to use Meteor's subscribe system to call an external service and have the results published through a subscription to the client. While I'm not sure this is really a better way to go then just using a meteor method or calling the service form the client, it does have interesting possibilities.
What I am curious about now is can I do this the other way around too, have client issue an insert or update to the collection on the client side, and have the server side catch it, redirect it to a service instead and then return the result? This would allow for some of the built in optimistic UI stuff to still work on the client, and the client to get notified if the update service call failed. Any ideas how I might go about doing this?

Check database for changes via long polling

Im creating a chat app in ASP.NET MVC3.
im using long polling and AsyncController to do so
when a user posts a chat its saved in database , to retrieve should i constantly check database for change in record or after definite interval
or is there an better/ efficient way of doing it
i came across this question but could not get a usable answer.
You may take a look at SignalR for an efficient way. Contrary to the standard polling mechanism (in which you are sending requests at regular intervals to check for changes), SignalR uses a push mechanism in which the server sends notifications to connected clients to notify them about changes.
Since you're already using long polling and an asynccontrolller, why not create a message pool? Take a look at this solution.
In a nutshell, instead of just writing the updated chat to the database, you should also stick it in some sort of queue. Then each user's async thread is listening to that pool waiting for a message to appear. When one appears return the data to the user through your normal operation. When all listening threads have picked up the message it can be removed from the queue. This will prevent you from having several threads hammering your database looking for a new message.
You can give PServiceBus(http://pservicebus.codeplex.com/) a try and here is a sample web chat app(http://74.208.226.12/ChatApp/chat.html) running and does not need database in between to pass message between two web clients. If you want to persist data in the database for logging sake, you can always subscribe to the chat message and log it to database.

Generally speaking, how do I implement a realtime monitoring system?

Suppose I have either an ASP.NET displaying my results, or a Silverlight client. And I'd like to show the current status of my server, or embedded device. (pretend the device reads temperature and humidity stats)
How should I send the status information from my device to the front end? Should I poll the device and save the results to SQL, Azure Table, or the like? (Azure is a technology that fits with this project for other reasons. That's why I mention it)
Or should I create a WCF service that polls the device directly and returns the current status.
What makes more sense?
In either ASP.NET or Silverlight you are going to have to poll from the client (web page or Silverlight app) to the backend to get the current status. In ASP.NET I'd look into doing this via an AJAX poll to a service using Javascipt (look at using Jquery or something similar to make this easier).
In silverlight you will need to have some sort of service configured to return the results and poll it using the Timer control running on a seperate thread.
You can also using a "push" binding within your silverlight app. Basically instead of you manually polling the server, the server will send you a push notification anytime it deems it necessary to let the client know of any change.

Resources