防止命名管道冲突
我们有一个 .NET 程序,它使用 WCF 来侦听来自另一个进程的通信。我们使用命名管道。
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/’,因为另一个管道端点已在侦听该名称”。
我的假设是另一个程序已经在使用命名管道。是否有解决方法,或者计算机上只能有一个程序使用命名管道?我从其他问题中得到的印象是,您可以为管道设置一个“名称”,这样它就不会与其他进程冲突,您如何做到这一点?
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();
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以一次使用多个命名管道。查看 Juval Lowy 的《Programming WCF Services》一书中的 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:
Which should avoid name conflicts.