There is one solution I could think of, but it feels a bit weird and I'm not really confident.
The server offers a generic subscription method for each of the lists. The name of the list is passed as parameter. On a change of any list, the server sends the name of the changed list together with the changed item. The issue is, the item could not be passed usually, because the callback contract has only a single "ListWasChanged" method (I absolutely want to avoid having a new callback method for each of the lists, see question).
However, this can be solved by passing the changed item serialized as string. By using NetDataContractSerializer, the client can easily reconstruct the serialized item and pass it to the correct handler for each list.
What do you think of this? Is this feasible? At first I thought this hurts the performance too badly, but on second thought, we have to serialize each item anyway. The only added performance hit is the serialization of the string, which should not be too much.
Since this may sound a bit confusing, here's an implementation in pseudo code:
server:
// let's call it SyncList - a list that sends updates on changes
class SyncList<T> : List<T>
{
// this is called on every change of the list
void OnListChanged<T (string name, T item)
{
// serialize the item
string ser = NetDataContractSerializer.Serialize(item);
// send the item together with the name of the list
WcfCallbackChannel.ListChanged (name, ser);
}
}
client:
// this stores each of the lists
Dictionary<string, List<T>> _Lists;
// the list callback implementation
class WcfCallbackImplementation : IWcfCallbackContract
{
// called on every change of ANY list
void ListChanged (string name, string item)
{
// get the item back
var item = NetDataContractSerializer.Deserialize (item);
// add/remove/update item
_Lists[name].Add (item);
}
}