0

RESULT: Stupid mistake by yours truly. Adding my client to the service's Dictionary incorrectly was causing the fault. I was looking for the problem in all the wrong places.

I have a named pipe WCF service with a callback. It reports USB device plug in events to clients. The problem I have is that if I quit the client and restart it, I always get a channel fault. When I exit the client I call code as follows:

        public void Dispose()
        {
            try
            {
                if (factory.State == CommunicationState.Opened)
                {
                    proxy.UnSubscribe(_clientName);
                    factory.Close();
                }
                else
                {
                    factory.Abort();
                }
            }
            catch (Exception)
            {
                factory.Abort();
            }
         }

I create the channel as follows:

            NetNamedPipeBinding netPipe = new NetNamedPipeBinding();
            // Security is not worth it for this.
            netPipe.Security.Mode = NetNamedPipeSecurityMode.None;
            // The receive time on the client side is ignored. The time the callback session
            // is kept alive is determined by the receive time on the service side which is infinite.
            factory = new DuplexChannelFactory<IUsbBroker>(
                    new InstanceContext(this), netPipe,
                    new EndpointAddress("net.pipe://localhost/Gyannea/WCFCallbacks/UsbBroker"));
            try
            {
                proxy = (IUsbBroker)factory.CreateChannel();
            }
            catch (Exception)
            {
                factory.Abort();
            }

I newly added the try-catch in the channel/proxy creation to see if that was the problem when I restarted the client in attempt to try and recreate the channel again if it was faulted after aborting. It did not work.

Am I missing something fundamental here? Thanks!

Brian Reinhold
  • 2,313
  • 3
  • 27
  • 46

1 Answers1

0

How do you host wcf service.

If you are running on Windows Vista or later, a WCF net.pipe service will only be accessible to processes running in the same logon session other wise you need to have admin rights.You should host your service in windows service

please see the following post

Client on non-admin user can't communicate using net.pipe with services

Minimum OS Permissions required to create named pipe (WCF)

Community
  • 1
  • 1
Mahesh
  • 2,731
  • 2
  • 32
  • 31
  • I am self-hosting the service and running the executable in admin mode (it won't connect at all without running in admin mode). In the mean time I am able to connect to the service using N instances of the same client. However, when I exit client #n and then restart it, I cannot connect. The remaining clients are still fine. The client is NOT in admin mode. Does the client need to be in admin mode? It is a problem with multiple instances? Maybe I am not using the duplex channel correctly (WCF is completely new to me!) – Brian Reinhold Jan 27 '14 at 10:28
  • It turns out that I was improperly adding my client to the service's Dictionary incorrectly. Stupid mistake that cost me two days of non-stop hair pulling. – Brian Reinhold Jan 27 '14 at 11:49
  • Good to hear u manage to solve your issue. this is blog post discuss about wcf duplex communication with namepipe http://dotnet-experience.blogspot.com.au/2012/02/inter-process-duplex-communication-with.html – Mahesh Jan 27 '14 at 11:54
  • Reading your comments actually helped me find the bug. But I will take any help trying to understand WCF that I can. Its been a lot to swallow in that last 15 days. – Brian Reinhold Jan 27 '14 at 17:56