防止命名管道冲突

发布于 2024-08-19 12:38:04 字数 506 浏览 5 评论 0原文

我们有一个 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

偏爱自由 2024-08-26 12:38:04

您可以一次使用多个命名管道。查看 Juval Lowy 的《Programming WCF Services》一书中的 ServiceModelEx。您将看到,当他创建命名管道时,他使用的代码如下所示:

Uri baseAddress = new Uri("net.pipe://localhost/" + Guid.NewGuid().ToString());

这应该避免名称冲突。

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());

Which should avoid name conflicts.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文