I have one WCF service that exposes two operations - IncrementList() and GetList(). Client B connects to the service, calls GetList() and displays to the user. Client A has the ability to update this list by calling IncrementList().
I want Client B to get notified when IncrementList() is called so it can call GetList() again to display the updated data.
Could you please outline how you'd implement this? CallBacks? Duplex? Publisher/Subscriber?
Anything new in WCF 4.0 that aids in this scenario?
Thanks!
Something you should decide up front is if you want to push the whole list when its incremented (heavy) or just the updated item to each client. The code below is for push whole list but easy to modify this just to push the updated object (recomended).
At app start Client B should call
Register_client
and thenGetList
. Subsequently it will be notified via call back when list is incremented (the client needs to implient this interface)The call
GetList
requires a duplex channel andSessionMode.Required
.Your server should impliment:
Your client should impliment:
Register client just needs store client callback interface for use when list is incremented something like:
Where:
The impliementation of
IncrementList
should do a callback to push new list (or better just the new object that was added to list) to client - something like:The callback implimentation (client side) looks something like:
Probably this callback implimentation needs a reference to some object that holds the list data - probably this is passed in to contructor (not shown).
When you instantiate your proxy object you will need to pass an instance of callback to the proxy constructor - something like: