开发者

Prevent Named Pipes Conflict

开发者 https://www.devze.com 2022-12-17 01:10 出处:网络
We have a .NET program that uses WCF to listen for communication from another process.We used named pipes.

We have a .NET program that uses WCF to listen for communication from another process. We used named pipes.

ServiceHo开发者_如何学Gost 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消