title: Use WCF to broadcast/notify different object?
body: <p>Just... doing some practices.</p>
  
  <p><strong>Structure:</strong></p>
  
  <p>A Client WPF App and a Server WPF App, both of them Self Host a WCF service.</p>
  
  <p>Client WPF contains a View, which contains the ListBox</p>
  
  <p><strong>What I want to do:</strong></p>
  
  <ol>
  <li><p>Server WPF will create channels to the Client's WCF and constantly Send Message.</p></li>
  <li><p>Client's WCF will receive the message and boardcast to any classes that subscribe it. (Or maybe I will say the classes that observe it).</p></li>
  <li><p>In this case, the Client's View should receive message and put into the listbox.</p></li>
  </ol>
  
  <p><strong>Problems:</strong></p>
  
  <p>So the problem is how do I let the View observe the WCF? Or get notify by the WCF?</p>
  
  <p>The Client's WCF is created by using ServiceHost myHost = new ServiceHost(typeof(MyClient));</p>
  
  <p>How can I let the WCF have reference to my Client's View and do the notification?</p>
  
  <p><strong>Throught:</strong></p>
  
  <ol>
  <li><p>Somehow hardcoding the Client's WCF to have the View reference internally (this...doesn't make sense)</p></li>
  <li><p>Observer Pattern? Make a static Subject class tht's implement Client's WCF Interface. 
  In the Client's will routers all the methods calls to Subject class.  The View will also implement Client's WCF Interface and attaches to Subject class.  Finally Subject class will routers calls to all the Views.... </p></li>
  </ol>
  
  <p>Something like this:</p>
  
  <pre><code>public class ClientServiceObserver : IClient
  {
      static List&lt;IClient&gt; _observers = new List&lt;IClient&gt;();
  
      public static void Attach(IClient client)
      {
          _observers.Add(client);
      }
  
      public static void Detach(IClient client)
      {
          _observers.Remove(client);
      }
  
      public void SendCallbackMessage(string message)
      {
          foreach (IClient client in _observers)
          {
              client.SendCallbackMessage(message);
          }
      }
  }
  </code></pre>
  
  <p>3.Everything similar to option 2, but instead of router all calls everywhere,  might as well let WCF just notify Subject class there is update, then View will just get notify and create channel to Server to get it own data.....</p>
  
  <p>All above options doens't really sounds good... and option 2 I don't even know if that's Observer Patterns anymore....</p>
  
  <p>I wonder what will be the best practice to do it?</p>