I have a web service that takes user location periodically.
I want to create a desktop application that takes those values and shows the real time position of user on a map automatically.
What is the best method I can follow to get real time updates?
Can I use Ajax? Does it support auto refresh?
Is there a better method which supports auto refresh and also display real time data?
Thank you..!
Check out the SignalR library. There is a server-part and a clients part (Javascript, rich client) etc.).
You could trigger the update in the client if the WebService was called. So the client is notified and could update his data accordingly.
How many clients are connected? Maybe some other message bus like library would be more appropriate?
Related
I have an application with one DB which is used by many users. Whenever one user makes changes, we save the changes to the database.
Now, I need to notify other logged-in users about this change. How can this be done?
I'm thinking - when the application succcessfully saves / updates the data in the database, the application will send a notification to the connected clients with the new record updated or added.
I'm using C# and SQL Server database.
Your immediate options are push-based notifications with something like a message bus, or polling loops on known ids.
Message busses operate on publish-subscribe models which work well for Windows applications. Have a look at MassTransit or MSMQ as a starting point. There are plenty of options out there. They can be combined into web apps using something that essentially wraps a polling loop with the client like SignalR.
Polling-based options work typically on a timer and do quick timestamp or version # checks against the database, reloading a record if a difference is found.
Push-based are more efficient but only notify of changes between supported applications. (Client to Client) they don't detect changes by applications that don't participate as publishers, nor do they see changes made directly to the database.
Polling-based options cover all changes, but are generally slower and require a schema that has version information to work effectively.
I have a functionality where I need to remind the customers about their appointments before the time interval set while creating the appointment.
Example:
A customer is logged into the system today at 4:00PM.
If a customer has an appointment set today at 5:00PM , and the reminder minutes as 10.
This invokes a popup with beepsound that has to appear today at 4:50PM(i.e 10 minutes before the actual appointment start time).
I have all appointments with start time, end time , (along with the dates) stored in backend table for number of customers.
Please guide me to achive the following in realtime :
(1) to invoke this popup at 4.50PM
(2) play the soundfile stored in the database
From my search,there is a way to do this using signalr concept in mvc. I went through the sample for chat application in this lnk.
http://www.asp.net/signalr/overview/getting-started/tutorial-getting-started-with-signalr
This invokes the hub when a event occurs. but in my application it has to work as a reminder to show the popup if the start time matched the current time. how to get this in real time. Any idea can help me.
This could be a good situation to use WebSockets. (Take a look at Socket.IO, and it's .NET version SocketIO4Net)
The idea would be to have a business logic server side to manage what customer has an appointment to be reminded. Then it uses the WebSocket to send the reminder signal. If the customer is logged in, the js client side would catch the signal and you decide how you want to show it.
To play the sound stored in the database, you could do an action server side that returns the sound file or something, and then use an HTML 5 tag to play the sound.
Hope this helps.
Everything can be done but as ChristianDev says SignalR does not work like this out of the box... I think you can do this with SignalR anyway but you have a few challenges...
You have to maintain state on the server for the clients appointment
This state have to be persistent between connection, when a client navigates between pages
When an event fires you have to send the message to the correct client
If that client is between pages (offline) at the moment that message have to be stored until the client gets back online and then be sent to him/her.
EDIT: It seemed like a fun thing to write so a wrote a simple notification application. You can probably port it to SignalR pretty easy. Realtime Notification Sample
You could change the approach, and use a windows service, emailing/sms'ing the user to remind them of the appointment, this means that the user doesn't need to be logged into the web application to receive a reminder.
If you wanted to use technology such as SignalR, you would need to keep a record of connected users (and their username) and then when an appointment is due, you would need to trigger an event to send to the user in question, based on the unique connectionId.
SignalR, out of the box, doesn't work like this - but, take a look at my question here for some help : Update UI with SignalR and Knockout when manually updating DB
Edit: To add to this, if you're looking for a very nice notification plugin, then take a look at John Papa's ToastR, it's a small JS/Css plugin which notifies via a 'timed, outlook style notification'.
I need to tell the Database Handler that it should run a script which generates 300-500MB of data, then notify my C# application that the script has completed.
After that I need to get the newly created data to my C# application, manipulate it then send it to an FTP-server.
One way to do this would be to call the SQL-server via a web service, let the Database Handler run the script, then return the data. The C# application would then manipulate the data and finally send it by FTP. However because of the size of the data and the run-time of the script being around 1 hour this method is far from optimal.
Any suggestions on a better solution?
EDIT: I forgot to mention some important parts. SSIS was something I thought of as well. The problem is that the database is on a different server which doesn't have ports open for sending via FTP.
I would implement this as a service. Use the web service to allow users to request execution of the script (queue a request), but actually execute the script from the service (read the queue and perform the action). You have far greater control of the entire data gathering and delivery process from within the service.
My own strategy would be to develop a standalone application (installed on the server) to perform the data retrieval, manipulation and FTP transfer. This application could be executed by code in your ASP.NET application as a result of some user interaction perhaps, and could update the database as to its progress so that your user could have some feedback via the ASP.NET web interface (ajax polling or loading a status page).
Have you considered using SSIS? One of the things it is really useful for is controlling data-centric multi-step workflows.
I have one windows application which is listening to events of a device attached(on USB port) and passing event name to web service(In Real Time).
And I have a website on which I want to perform certain operations according to the event of device(In Real Time).
So I want to pass data or call function on website whenever a new event value is passed from windows application.
I tried to use timer on web page which is calling Web-service to get latest value. But the problem is that events are changing very rapidly.
Is there any way that web-service automatically send some data to my website? or any other solution.
Thanks in advance
With the best of my knowledge, I think you cannot just directly pass the data on your website from the web service, since the service itself doesn't know to which it is connected with.
For your scenario what I will do is, make a database with some required tables in it and store the data in there from a web method whenever it is called by your windows application, since your application is entirely built on .NET you can simply pass the DataTable object without having to parse the XML data on the other side. Now, make a web method that will return this data from the database. Call this web method from your website. When the data has been sent to the website, you can however delete it from the database so that the new data can then be sent in the next call.
It might help you!
I'm using c# to communicate with twitter and i need to code a schedule system to send twitter messages at a user defined date.
The messages to be sent are in a database with the date and time of deliver.
Which is the best method to check the db for scheduled messages and send it when the time arrives?
How accurate do you need the timing to be? Could you get away with polling the database every 5 minutes, saying "Tell me all the messages which need to be delivered before current time + 5 minutes" and then sending them all? (And marking them as sent in the database, of course.) Does it matter if they're a bit early or late?
You can do the scheduling on the C# side to make it more accurate, but unless you really need to I'd stick with a very simple solution.
(Depending on your database there may be clever ways of getting callbacks triggered etc... but again, I'd stick with the simplest solution which works.)
In addition to the windows service option (or background thread), you could just set up a scheduled task to run an app that polls the DB and sends the tweets once every defined interval.
Windows schedules can be setup using C# if needed and are really easy to set up manually.
There are several ways to do this, but I guess the best way is to set up a Windows Service that will periodically poll (frequency is up to you) the DB for any scheduled tweets that hasn't been sent.
Needless to say you'll need to handle scenarios such as the Internet connection or DB being down, etc.
In fact the solution consists in using a windows service but it can't communicate directly with the ASP.NET MVC app. I've added a Web Service that handles the task and a System.Threading.Timer in Windows Service to periodically call the Web Service.