Search code examples
wcfnamed-pipesduplex

Multiple WCF named pipe clients connecting without repeatedly invoking the endpoint's constructor?


I've got a WCF server/client setup using named pipes, and my client connects to the host process (already running) as follows:

var pipeFactory = new DuplexChannelFactory<IArbiter>(this, new NetNamedPipeBinding(), new EndpointAddress(new Uri("net.pipe://localhost/IArbiter")));
arbiter = pipeFactory.CreateChannel();

This is fine for the first client connecting, but when the second client connects, a new instance of the IArbiter implementation is created (the arbiter's constructor is called every time a connection happens).

Is there a way to find the "existing" instance of that arbiter at the endpoint address?


Solution

  • Figured it out, just need to set this above my class implementation:

    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]