Ok so I am changing the way that my service pushes out notifications to clients. Right now the way that ServiceModelEx is working is that if any client is subscribed to an event it messages all subscribed users regardless if the message is for them. At the client I determine whether or not the message is for them. As you can imagine that can generate a lot of network traffic especially when you only need to send to certain clients.
Right now I am using TransientSubscriptions
.
I tried debugging the code but the only thing I can tell is that each subscriber is stored as some type of Generic CallbackChannel
.
Each TransientSubscriber is defined this way.
T subscriber = OperationContext.Current.GetCallbackChannel<T>();
When it adds a TransientSubscriber it executes this.
static void AddTransient(T subscriber, string eventOperation) {
lock (typeof(SubscriptionManager<T>)) {
List<T> list = m_TransientStore[eventOperation];
if (list.Contains(subscriber)) {
return;
}
list.Add(subscriber);
}
}
If there is a better way then I am open to suggestions. I just want to send a notification to 1 client instead of all clients.
Also here is an msdn article on ServiceModelEx.
Ok so here is what I did. I added another generic class but this one holds a userID and the Generic CallbackChannel.
public class Subscriber<T> {
private int _UserID;
private T _Subscription;
public int UserID {
get { return _UserID; }
set { _UserID = value; }
}
public T Subscription {
get { return _Subscription; }
set { _Subscription = value; }
}
}
I then switched every parameter in ServiceModelEx that held T to hold Subscriber<T>
. After that I created a new FireEvent
called FireUserEvent
that then passes the UserID down through the GetTransientList
methods, which I also created new ones for to pass in the UserID. That way it only returns the Subscriber<T>
for said User.