Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF Multiple Apps using NetNamedPipe

I am trying to run multiple WCF Service hosting apps on the same Machine.

I want to run multiple Applications - not multiple services in one application.

var host = new ServiceHost(typeof(MyClass1), new Uri[] { new Uri("net.pipe://localhost") });
host.AddServiceEndpoint(typeof(ISomeInterface),  new NetNamedPipeBinding(), "FOO");
host.Open();

I change "FOO" for every app, but still can not start multiple Services. Guess its pretty simple, but im stuck :(

Regards

like image 314
Jaster Avatar asked Mar 16 '11 13:03

Jaster


1 Answers

Approaching it like this will do what you want, I believe:

string relativeUriPart = GetUniquePartFromConfigOfThisApplicationInstance();
var host = new ServiceHost(typeof(MyClass1)); // No base addresses specified
host.AddServiceEndpoint(
    typeof(ISomeInterface),  
    new NetNamedPipeBinding(), 
    "net.pipe://localhost/" + relativeUriPart); // Specify absolute URI for endpoint
host.Open();

This is because, if you specify a base address which uses the net.pipe scheme, it is this base address which is used to derive the pipe name used by the listener [see edit below], and this is the same in each application instance, so only the first application's listener can create the pipe - the others fail as you have noted.

Using the absolute URI at the endpoint level, with no base address, the listener is created with a pipe name derived [see edit below] from the full absolute URI, which is different in each application instance, and so each application's listener can create its own distinct pipe without any problem.


EDIT: To be more precise, the pipe name itself is not derived from the service address at all - it is a GUID which changes each time the service is opened. What is derived from the service address is the name of a shared memory object via which the actual name of the pipe is published to prospective clients. See here for more details.

like image 147
Chris Dickson Avatar answered Nov 09 '22 09:11

Chris Dickson