views:

578

answers:

2

I have two .NET C# windows forms applications that are communicating with each other via WCF named pipes. One of the applications is hosting a WCF service and the other is the client. Communication is working fine, the client can call service methods and callbacks work fine, etc. However, one issue I am having is if the host application shuts down, the client is not able to detect that the pipe is no longer available. I have tried registering event handlers on the pipe for all events (Closing, Closed, Faulted), but these never get called when the host application shuts down. Also, if I try to check the pipe state in the client with the pipe.State property, I get back a state of Opened even if the pipe is Faulted. Then of course it throws an exception if I try to call a service method. I either need to have my client application either be notified that the service is closing, closed, or faulted, or I need to be able to detect it before I make each service method call.

Does anyone have any working examples of this scenario?

A: 

I do not think that the server can tell the client that it is down without the client actually making a call to the server.

  • If the server is down it will not do anything
  • If the pipe is closed it does not have anything to communicate over

Best solution that I can think of is that you make the call within a try catch, and then handle the error when it happens.

Shiraz Bhaiji
+1  A: 

Using WCF over named pipes on .NET 3.5 works for me. Here is an example

    public ClientUpdaterTray()
    {
        InitializeComponent();
        InstanceContext context = new InstanceContext(new ClientUpdaterServiceCallback());
        client = new ClientUpdaterTrayServiceClient(context);

        client.InnerChannel.Faulted += new EventHandler(InnerChannel_Faulted);
        client.InnerDuplexChannel.Faulted += new EventHandler(InnerDuplexChannel_Faulted);
    }

    void InnerDuplexChannel_Faulted(object sender, EventArgs e)
    {
        // Connection faulted
    }

    void InnerChannel_Faulted(object sender, EventArgs e)
    {
        // Connection faulted
    }
coreywride