Two unique named pipes conflict and InvalidCredentialException

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 :)

+6
source share
1 answer

Re problem 1:

WCF NetNamedPipeBinding uses a named shared memory partition to publish to its customers the actual name of the channel through which the service can be called. The name of the pipe itself is the GUID that is regenerated each time the service host is opened. This is the name of the shared memory section used to publish the service, which depends on the service URL. If a base address is specified, the base address is used to obtain this name.

This means that you can only use one WCF service application at a time that uses a specific base address for its NetNamedPipe endpoints. If you try to run the second one, it will not be thrown using an AddressAlreadyInUseException, because it finds that the name of the WCF that it wants to use for the publication location (obtained from the base address) has already been accepted by another application.

If you do not provide a base address and provide each service with an absolutely unique service URL, then the publication location name will now be retrieved from the full absolute URL and there will be no name conflict between applications. This is a completely efficient and secure way to listen to multiple WCF services called pipe.

Re problem 2:

On the service side, you can use anything for the host name part of the service URL. This is due to the default setting of HostNameComparisonMode for HostNameComparisonMode, because the WCF algorithm, which gets the name for the shared memory publishing location, replaces the wildcard for the host name, see here to enable the configured host mapping mode.

However, on the client side, the service URL is limited: the host part must indeed resolve to localhost (i.e. it is localhost , the correct IP address, or the correct machine name).

+13
source

Source: https://habr.com/ru/post/914406/


All Articles