Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Server interface
- [ServiceContract(CallbackContract = typeof(IGUIService))]
- public interface IServerService
- {
- [OperationContract(IsOneWay = true)]
- void Subscribe();
- [OperationContract(IsOneWay = true)]
- void Unsubscribe();
- ...
- }
- //Client interface
- [ServiceContract]
- public interface IGUIService
- {
- [OperationContract(IsOneWay = true)]
- void MessageCallback(string Message);
- }
- [ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]
- public class ServerService : IServerService
- {
- internal event SettingsUpdatedHandler SettingsUpdated;
- internal delegate void SettingsUpdatedHandler(ServerService adminPort, EventArgs e);
- private static List<IGUIService> Clients = new List<IGUIService>();
- public void Subscribe()
- {
- IGUIService callback = OperationContext.Current.GetCallbackChannel<IGUIService>();
- if(!Clients.Contains(callback))
- Clients.Add(callback);
- }
- public void Unsubscribe()
- {
- IGUIService callback = OperationContext.Current.GetCallbackChannel<IGUIService>();
- if (Clients.Contains(callback))
- Clients.Remove(callback);
- }
- }
- internal void SendMessage(string message)
- {
- for(int i=Clients.Count - 1; i >= 0; i--)
- {
- IGUIService callback = Clients[i];
- if (((ICommunicationObject)callback).State == CommunicationState.Opened)
- callback.MessageCallback(message);
- else
- Clients.RemoveAt(i);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement