Self-hosting WCF over named pipes

In VS13:
I want to call a WCF service (via a WCF service library) either from a test app or from a windows service.
Both should self-host using a named pipes port.

I keep getting timeout in the client:
There was an error reading from the pipe: The pipe has been ended.

So What are reasons for local Windows named-pipes to fail?

Well I haven’t found
– PipeFirewall
– File sharing service not running
– Windows firewall blocking

So now I’ll just store this sample for another time.

Intersting is that the WCF service library app.config is read by VS13 and it starts the service on those endpoints (basicHttp), too.

Note: InProcFactory is a library from Using that made no difference.

Server and Client code:

        private void buttonStart_Click(object sender, EventArgs e)
            ICleanUpMiniService wcfSvc = null;
            textBox1.Text = "";

            bool useInProFactory = false;

            if (!useInProFactory)
                // Create the ServiceHost.
                Uri baseAddress = new Uri("net.pipe://localhost/mysln/" + Guid.NewGuid() + "/");
                //Uri baseAddress = new Uri("net.pipe://" + Environment.MachineName + "/mysln/" + Guid.NewGuid() + "/");
                using (ServiceHost host = new ServiceHost(typeof(CleanUpMiniService), baseAddress))
                    var binding = new NetNamedPipeBinding();
                    binding.ReceiveTimeout = new TimeSpan(0, 0, 15); //Cilent timeout
                    //binding.TransactionFlow = true;
                    const string relAddress = "cleanupminiservice";
                    ServiceEndpoint endpoint = host.AddServiceEndpoint(typeof (ICleanUpMiniService), binding, relAddress);

                        // Open the ServiceHost to start listening for messages. Since
                        // no endpoints are explicitly configured, the runtime will create
                        // one endpoint per base address for each service contract implemented
                        // by the service.

                        Debug.WriteLine("Service started. Available in following endpoints");
                        foreach (var serviceEndpoint in host.Description.Endpoints)
                        //Create service

                        Debug.WriteLine(endpoint.Name); //NetNamedPipeBinding_ICleanUpMiniService

                        //Open client using server endpoint
                        var factory = new ChannelFactory<ICleanUpMiniService>(endpoint);
                        //Open client using app.config client settings
                        //var factory = new ChannelFactory<ICleanUpMiniService>("NetNamedPipeBinding_ICleanUpMiniService");
                        wcfSvc = factory.CreateChannel();

                        //Use service
                        string[] args = {};
                        textBox1.Text = wcfSvc.Hallo("sss"); //.OnStop();//.OnStart(args);

                        Debug.WriteLine("returned from server");
                        // Close the ServiceHost.
                    wcfSvc = InProcFactory.CreateInstance<CleanUpMiniService, ICleanUpMiniService>();

                    //Use service
                    string[] args = { };
                    textBox1.Text = wcfSvc.Hallo("sss");//.OnStop();//.OnStart(args);

                    Debug.WriteLine("returned from server");
                    if (wcfSvc != null)

One Comment

Add yours →

  1. BTW: Got to run VisualStudio as admin – also the compiled test app.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: