Reputation: 2977
I'm developing an application (school project) which is a service + an external WPF UI. I've planned to use WCF for UI-to-service communication. Anyway, the service needs to notify the UI if some events occurs, and I'm looking for a simple way to do it.
Of course, any basic IPC would work, but I'd prefer not to mess up with pipes, mutex, events and so on.
In a native win32 app I'd have used a WM_USER
message, but as far as I have understood it's not natively supported by WPF.
Can someone point out some possible/best solution?
Thanks
Upvotes: 2
Views: 3218
Reputation: 2097
You can use WCF Callback Operations for notifying the client.
Upvotes: 3
Reputation: 21712
Are your service and application running on separate machines? If your service sends a notification while your app is not running, do you want to be notified when your app next runs? If so, your best option is Message Queuing.
Upvotes: 1
Reputation: 8531
One approach I've used is a shared database table that acts as a queue. Your UI app keeps track of the last record it's seen (either an index or timestamp) and periodically polls for new events. Bind your queries and updates with transactions to prevent concurrency problems. One advantage of a database is that it persists the events which help with debugging and crashes. System.Data.Sqlite, RavenDB, and Sql Server Compact Edition are good choices.
Another alternative is to use ZeroMQ as a publish/subscribe message system via TCP/IP. ZeroMQ is very easy to setup and can handle high message volumes.
Both the database and ZeroMQ approach let you put the UI app on a remote machine instead of requiring it to be on the service host.
I also recommend that you define your events as a class and serialize it to a string regardless of whether you're using a database or ZeroMQ to pass events. I recommend ServiceStack's excellent, easy to use JSON serializer.
Upvotes: 2
Reputation: 28980
You can try EventAggregator
in order to send notification (Subscribe + Publish methods)
Link : http://msdn.microsoft.com/en-us/library/ff921122%28v=pandp.20%29.aspx
Upvotes: 0