WCF : Service does not work for multiple clients
<p>I have a self-hosted WCF Service with a peer-to-peer binding. I'm using a DuplexChannel for getting responses. The callback itself is working. I'm saving the callbacks in a static Dictionary. When a client logs in, the callback is added to the Dictionary. But  when I create multiple clients, the static variables are empty. </p>

<p>This is my Service interface : </p>

<pre><code>[ServiceContract(SessionMode = SessionMode.Allowed, CallbackContract = typeof(ICallbackService))]
public interface IService
{
    [OperationContract(IsOneWay = true)]
    void Login(string email, string password);

    [OperationContract(IsOneWay = true)]
    void Logout(int userId);
}
</code></pre>

<p>My IService implementation : </p>

<pre><code>  [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple)]
public class Service : IService
{
    private ServiceHost host = null;
    private DuplexChannelFactory&lt;IService&gt; channelFactory = null;
    private IService service = null;

    private static Dictionary&lt;ICallbackService, ICallbackService&gt; pair = new Dictionary&lt;ICallbackService, ICallbackService&gt;();
    private static Dictionary&lt;string, ICallbackService&gt; clients = new Dictionary&lt;string, ICallbackService&gt;();

    private ICallbackService callback;



    public Service(InstanceContext context)
    {
        startService(context);
    }


    private void startService(InstanceContext context)
    {
        host = new ServiceHost(this);
        host.Open();
        context.Open();
        channelFactory = new DuplexChannelFactory&lt;IBattleshipService&gt;(context, "Endpoint");
        channelFactory.Open();
        service = channelFactory.CreateChannel();

          callback = context.GetServiceInstance() as ICallbackService;
    }

    private void stopService()
    {
        if (host != null)
        {
            if (host.State == CommunicationState.Closed)
            {
                channelFactory.Close();
                host.Close();
            }
        }
    }

    public void Login(string email, string password)
    {

        User user = getAllUsers().Find(u =&gt; u.Email.ToLower() == email.ToLower() &amp;&amp; u.Password == password);

        if (user != null)
        {
            Console.WriteLine("user : " + email + "    has logged in");
            clients.Add(email, callback);
            callback.Authenticate(true);
        }
        else callback.Authenticate(false);
    }

    public void Logout(int userId)
    {
        string email = getUser(userId).Email;
        clients.Remove(email);
        stopService();
    }
}
</code></pre>

<p>My callback service : </p>

<pre><code>public interface ICallbackService
{

    [OperationContract(IsOneWay = true)]
    void Authenticate(bool authenticated);
}
</code></pre>

<p>The implementing callback service class in my client application : </p>

<pre><code> [CallbackBehavior(ConcurrencyMode = ConcurrencyMode.Single, UseSynchronizationContext = false)]
public class Client : Service.ICallbackService, 
{
    public bool Authentication { get; internal set; }

    public Client()
    {
    }

    public void Authenticate(bool authenticated)
    {
        Console.WriteLine("authentication : " + authenticated);
        Authentication = authenticated;
    }
</code></pre>

<p>}</p>