1
votes

I have two applications that exposes WCF endpoints using named pipes for communication.

One app is a WPF user application and the other one is a Windows Service, when I make a call from the user app to the win service it's fine, but whenever the Windows Service calls the WPF's application endpoint I receive an System.ServiceModel.CommunicationObjectFaultedException stating that the Communication Object cannot be used while it's in faulted exception.

The funny thing is that if I copy and paste my code to a Console Application it works just fine.

Here is the code I'm using to create the communication object

        public void CallService()
        {
            using (var channel = GetServiceClient())
            {
                channel.Open();

                var service = channel.CreateChannel();

                service.DoFoo();
            }
        }

        private static ChannelFactory<IFooService> GetServiceClient()
        {
            return new ChannelFactory<IFooService>(
                new NetNamedPipeBinding
                {
                    Security = new NetNamedPipeSecurity { Mode = NetNamedPipeSecurityMode.None }
                },
                @"net.pipe://barAddress/fooService");
        }
1

1 Answers

0
votes

After some research, I found out that NetNamedPipesBinding is not the same as the default Named Pipes used for communication, thus having some limitations.

What happens is that a Windows Service does not run in the same user session as a desktop app and NetNamedPipes can't go from the service context to a user session, just like it can't cross the boundary between two different user sessions.

The alternatives I found is to use a pure Named Pipes approach, without WCF or change the contract type to a Duplex Service and make the user app open the channel to the service.