title: wcf callback reference
body: <p>I have a desktop app with a duplex WCF service, but I have some troubles using the callback.</p>
  
  <p>The service is started as following in main of program.cs:</p>
  
  <pre><code>ServiceHost svcHost = new ServiceHost(typeof(PeriodicService));
  svcHost.Open();
  Console.WriteLine("Available Endpoints :\n");
  svcHost.Description.Endpoints.ToList().ForEach(endpoint =&gt;   Console.WriteLine(endpoint.Address.ToString() + " -- " + endpoint.Name));
  </code></pre>
  
  <p>For the service I created a subscribe function where the callbackchannel is saved in a global variable, then the callback uses that global variable to talk back to the client (there will be only one client connecting).</p>
  
  <pre><code>IPeriodicCallback callbackClient;
  
  public IPeriodicCallback Proxy
  {
       get
       {
          return this.callbackClient;
       }
  }
  
  public void joinPeriodicService()
  {
      Console.WriteLine("Client subscribe");
      this.callbackClient = OperationContext.Current.GetCallbackChannel&lt;IPeriodicCallback&gt;();
  }
  </code></pre>
  
  <p>The thing I want to do now is call the callbackclient from an other class. 
  In the other class I created the service as:</p>
  
  <pre><code>private PeriodicService periodicService = new PeriodicService();
  </code></pre>
  
  <p>And I try to write data to it using:</p>
  
  <pre><code>if(this.periodicService.Proxy != null)
  { 
       this.periodicService.Proxy.On1MinuteDataAvailable(tmpPeriod);
  }
  </code></pre>
  
  <p>However the proxy stays null, I also tried to move the proxy part to the class but this also results in it staying null.</p>
  
  <p>When the client connects I nicely get the message "Client Subscribe" but it seems there are two instances running of the periodicservice.</p>
  
  <p>But my problem is I don't see an other way to access the periodicservice then creating it in my class, or is it also already created by the svcHost?</p>
  
  <p>Can ayone point me in the right direction?</p>