The easiest way is to provide the customer with a key value representation in the subscribe method of your service. Then you can save the callback channel in the dictionary. This dictionary should probably be a static or singleton class whose service life is longer than the service class service life, since most service classes have a PerCall lifetime and are deleted after the service call ends. Beware of threading issues!
The callback channel may be malfunctioning at any time, either on the client side or on the service side. The service should handle the possibility of a faulty channel and remove the faulty channel from the dictionary. WSDuallHttpBinding is a stateless binding, so any errors in the client will not be detected on the service side until the service side tries to cause them. NetTcpBinding will raise the ChannelFaulted event if the client enters an error state. For this reason, I would recommend NetTcpBinding if it meets your requirements.
public bool Subscribe(string id) { ICallback callback = OperationContext.Current.GetCallbackChannel(); if (!_activeCallbackChannels.Contains(id)) { _activeCallbackChannels.Add(id, callback); return true; } else { return false; } }
source share