Greg,

There is a similar good example online of a WCF chat here :
http://www.codeproject.com/Articles/19752/WCF-WPF-Chat-Application

and, what follows is a very abridged version of what I've done in the past:

Ensure your server endpoint is PerSession:
/[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public class TradingClient/

Obtain the callback channel when the user logs in:
/public LoginResponse Login(LoginRequest request)
        {
var clientCallback = OperationContext.Current.GetCallbackChannel<IClientCallback>();/


Add the current instance of /TradingClient and //IClientCallback/ to a new object, lets call it ClientConnection /var clientConnection = new ClientConnection { Client = this, Callback = clientCallback /}

and then add /clientConnection /to a list, which is your global list of connected users.

Hope this helps.


On 5/05/2012 7:47 AM, Greg Keogh wrote:

Folks, I have to write a client-server app where the server is a WCF service over tcp binding and the clients are WinForms apps on the LAN. I have to implement callbacks to clients so that if one client updates the database then the server can broadcast this to all clients.

I've done this previously with Remoting and the trick is to call a service method like Login(user,password,callback) where callback is a MarshalByRefObject which implements a callback method. The server has to keep a collection of these callbacks and then loop through them to broadcast back to the clients. The error handling is a bit fiddly but overall it works very well. It works because the channels to the clients are open and I can call back over them at any time.

I can't figure out how to implement the same behaviour in WCF. I'm confused by the lifetime of the channels and I don't know how to broadcast back to all clients. I don't even know what to hold in a collection on the server side to reference the client's callbacks. I'll keep web searching in the meantime for a sample of what I want, but it might waste a lot of time and I was wondering if anyone here has done this with WCF before. Any advice would be most welcome. I'll post the answer back if I ever find it.

Cheers,

Greg

Reply via email to