title: WCF - Client callback vs. polling for "keep list of subscribers"
body: <p>I want to create a simple client-server example in WCF. I did some testing with callbacks, and it works fine so far. I played around a little bit with the following interface:</p>
  
  <pre><code>[ServiceContract(SessionMode = SessionMode.Required, CallbackContract = typeof(IStringCallback))]
  public interface ISubscribeableService
  {
      [OperationContract]
      void ExecuteStringCallBack(string value);
  
      [OperationContract]
      ServerInformation Subscribe(ClientInformation c);
  
      [OperationContract]
      ServerInformation Unsubscribe(ClientInformation c);
  }
  </code></pre>
  
  <p>Its a simple example. a little bit adjusted. You can ask the server to "execute a string callback" in which case the server reversed the string and calls all subscribed client callbacks.</p>
  
  <p>Now, here comes the question: If I want to implement a system where all clients "register" with the server, and the server can "ask" the clients if they are still alive, would you implement this with callbacks (so instead of this "stringcallback" a kind of TellTheClientThatIAmStillHereCallback). By checking the communication state on the callback I can also "know" if a client is dead. Something similar to this:</p>
  
  <pre><code>Subscribers.ForEach(delegate(IStringCallback callback)
                      {
                          if (((ICommunicationObject)callback).State == CommunicationState.Opened)
                          {
                              callback.StringCallbackFunction(new string(retVal));
                          }
                          else
                          {
                              Subscribers.Remove(callback);
                          }
                      });
  </code></pre>
  
  <p>My problem, put in another way:</p>
  
  <ul>
  <li>The server might have 3 clients</li>
  <li>Client A dies (I pull the plug of the laptop)</li>
  <li>The server dies and comes back online</li>
  <li>A new client comes up</li>
  </ul>
  
  <p>So basically, would you use callbacks to verify the "still living state" of clients, or would you use polling and keep track "how long I havent heard of a client"...</p>