WCF service using named pipes. I'm doing this now to communicate between the design surface of some WF4 activities and a visual studio extension.
Its very simple to do. I can't show all the code as some of it is wrapped up in helpers that control opening and closing the channel, but the definition is pretty simple and is done all in code.
You just need to define a binding
var binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.Transport);
binding.ReceiveTimeout = TimeSpan.FromMinutes(1);
create your channel
var channelFactory = new ChannelFactory<IServiceInterface>(binding, endpointAddress);
and you have to make sure that the endpoint address is guaranteed to be the same in both the client and server, which both share the same process but exist in different AppDomains. A simple way to do this is to scope the address to the process ID...
private const string AddressFormatString =
"net.pipe://localhost/Company/App/HostType/{0}";
private static string _hostAddress;
public static string HostAddress()
{
if (_hostAddress == null)
_hostAddress = string.Format(
AddressFormatString,
Process.GetCurrentProcess().Id);
return _hostAddress;
}
You'll have two actual copies of this (one in the client appdomain, one in the addin appdomain) but since they are both in the same process the host address is guaranteed to be the same in both and you won't run into issues where you have multiple instances of VS loaded at the same time (no freaking Running Object Table, thanks).
I keep this address code in the base host class. Opening the host channel is also pretty easy:
Host = new ServiceHost(this, new Uri(HostAddress()));
var binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.Transport);
Host.AddServiceEndpoint(typeof(IServiceInterface), binding, HostAddress());
Host.Open();