Prevent Named Pipes Conflict

别来无恙 提交于 2020-01-03 09:01:50

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/2118114/prevent-named-pipes-conflict

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!