There are two problems that I encountered last night that I solved now, but I am not 100% sure why what I did solved them, and was hoping that someone could offer some insight as I turned over many rocks and no luck!
First problem
The first problem is that I had two uniquely named channels that were in two separate programs:
- net.pipe: // local / superuniquepipe1
- net.pipe: // local / superuniquepipe2
However, the second program run will throw an exception (I believe it was an AddressAlreadyInUseException) when the ServiceHost is opened due to an already existing address.
The way I was creating these ServiceHosts was as follows:
Uri[] baseAddresses = new Uri[] { new Uri("net.pipe://localhost") }; this.host = new ServiceHost(this, baseAddresses); this.host.AddServiceEndpoint(typeof(IHostType), new NetNamedPipeBinding(), "superuniquepipe1"); this.host.Open();
So, first I have to specify the base address of localhost, and then specify the rest when adding the endpoint, as I decided to change this code as follows:
this.host = new ServiceHost(this); this.host.AddServiceEndpoint(typeof(IHostType), new NetNamedPipeBinding(), "net.pipe://localhost/superuniquepipe2"); this.host.Open();
Am I rightly saying that the reason is that it worked because it only checked the base addresses and not the endpoint that I was trying to add? And does the second code example use a valid / safe way to listen to multiple programs on "localhost"?
The second problem :
In an attempt to fix this, I changed the base address from localhost to several different unique lines, for example. "net.pipe: // rawrwhyisntthisworkingsadface", but I will get an InvalidCredentialException from a client trying to establish a connection (see code below).
I had the impression that a named pipe can literally be called anything, can anyone shed light on this one?
ChannelFactory<IHostType> factory = new ChannelFactory<IHostType>(new NetNamedPipeBinding(), new EndpointAddress("net.pipe://rawrwhyisntthisworkingsadface/superuniquepipe2")); IHostType proxy = factory.CreateChannel(); proxy.CallSomeMethodAndGetAnException();
Any input is welcome, as I said that I solved the problem and just want to know why my solution worked, but if you see a flaw in the way I solved it, and I can offer a better way to do it, do the following :)