如何在同一台机器上打开2个命名管道?

jav*_*red 2 c# wcf

我想在我的机器上运行我的程序的两个实例.每个实例都需要localhost命名管道:

_host = new ServiceHost(typeof(ManagementConsole),
            new Uri[]
            {
                new Uri("net.pipe://localhost")
            });

_host.AddServiceEndpoint(typeof(IManagementConsole),
     new NetNamedPipeBinding(),
     "PipeManagementConsole");

_host.Open();
Run Code Online (Sandbox Code Playgroud)

在我使用的程序的另一个例子中 PipeManagementConsole2

所以客户应该使用net.pipe://localhost/PipeManagementConsolenet.pipe://localhost/PipeManagementConsole2.

但是,Windows不允许我的程序的第二个实例运行,它声称net.pipe://localhost已经在使用(它是),我该如何解决这个问题?

jav*_*red 7

创建ServiceHost时应指定不同的地址,而不是在调用AddServiceEndpoint时.

这段代码工作正常:

_host = new ServiceHost(typeof(ManagementConsole),
                            new Uri[]
                            {
                                new Uri("net.pipe://localhost/2")
                            });

_host.AddServiceEndpoint(typeof(IManagementConsole),
    new NetNamedPipeBinding(),
    "PipeManagementConsole");

_host.Open();
Run Code Online (Sandbox Code Playgroud)

客户应该使用 "net.pipe://localhost/2/PipeManagementConsole"

但是这段代码不起作用:

_host = new ServiceHost(typeof(ManagementConsole),
                        new Uri[]
                        {
                            new Uri("net.pipe://localhost")
                        });

_host.AddServiceEndpoint(typeof(IManagementConsole),
    new NetNamedPipeBinding(),
    "PipeManagementConsole2");

_host.Open();
Run Code Online (Sandbox Code Playgroud)

如果net.pipe://localhost/PipeManagementConsole已经在使用中

我不知道为什么net.pipe://localhost/2/PipeManagementConsole比这更好net.pipe://localhost/PipeManagementConsole2


Roy*_*mir 5

你不能

在此处输入图片说明