I'm using a DuplexChannelFactory
to create a named pipe on net.pipe://localhost/test
. However, when I run my program, I get an error: Cannot listen on pipe name "net.pipe://localhost/" because another pipe endpoint is already listening on that name.
So I tried to see whether this was actually the case, by opening a powershell and typing in [System.IO.Directory]::GetFiles("\\.\\pipe\\)
, but there is no mention of localhost.
I then also tried to change the address net.pipe://localhost/test
to net.pipe://anything/test
but it still didn't work.
Finally I restarted the computer and it worked. But restarting the computer is not optimal, and I restarted it again earlier today and it broke again.
Could there be any other reason why I would get this error?
WCF Named pipes operate on a different system to regular nameed pipes. When you open a regular named pipe on localhost, you will get a pipe at \.\pipe\localhost
, but when you open a WCF pipe you will get \.\pipe\some-guid-xxxx-xxxx
. This generated GUID is consistent for WCF named pipes of the same name, which is why it works seamlessly. (see Prevent Named Pipes Conflict)
Now, in my code, I wanted to create a named pipe on localhost
. It didn't show up in [System.IO.Directory]::GetFiles("\\.\\pipe\\)
, because WCF uses a UUID.
The workaround I used in the end is to specify the pipe url as net.pipe\localhost\something_specific_to_me
and have an additional AddServiceEndpoint(...,"something_else")
, so that the final pipe could be connected to via net.pipe\localhost\something_specific_to_me\something_else
.