防止命名管道冲突 [英] Prevent Named Pipes Conflict
问题描述
我们有一个.NET程序,该程序使用WCF侦听来自另一个进程的通信.我们使用了命名管道.
We have a .NET program that uses WCF to listen for communication from another process. We used named pipes.
ServiceHost host = new ServiceHost(
typeof(Something),
new Uri[]
{
new Uri("net.pipe://localhost")
});
host.AddServiceEndpoint(typeof(ISomething), new NetNamedPipeBinding(), "Something");
host.Open();
在安装第三方.NET程序之前,该代码非常有效.现在,打开失败,并显示一条消息无法侦听管道名称'net.pipe://localhost/',因为另一个管道端点已经在侦听该名称了."
The code worked great until a third party .NET program was installed. Now the open fails with a message of "Cannot listen on pipe name 'net.pipe://localhost/' because another pipe endpoint is already listening on that name."
我的假设是其他程序已经在使用命名管道.有没有解决方法,或者计算机上只有一个程序可以使用命名管道?我从其他问题中得到的印象是,您可以为管道设置一个名称",这样它就不会与其他进程冲突,您该怎么做?
My assumption is that the other program is already using named pipes. Is there a workaround or can only one program on a computer use named pipes? I get the impression from other questions that you can set a "name" for a pipe so it doens't conflict with other processes, how do you do that?
推荐答案
您可以一次使用多个命名管道.从他的《 Programming WCF Services》一书中了解Juval Lowy的ServiceModelEx.您将看到他创建命名管道时,他使用的代码类似于:
You can use multiple named pipes at a time. Take a look at Juval Lowy's ServiceModelEx from his book Programming WCF Services. You will see when he creates named pipes, he uses code that looks something like:
Uri baseAddress = new Uri("net.pipe://localhost/" + Guid.NewGuid().ToString());
应避免名称冲突.
这篇关于防止命名管道冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!