WCF named pipe client notification

I have two Windows C.NET applications that communicate with each other through WCF called pipe. One application has a WCF service and the other a client. Communication is working fine, the client can call service methods, and callbacks are working fine, etc. However, one of the problems that I have is that the host application is disconnected, the client cannot detect that this channel is no longer available. I tried to register event handlers in the pipe for all events (Close, Close, Fault), but they are never called when the host application terminates. In addition, if I try to check the status of the pipeline in the client with the pipe.State property, I will return to the Open state, even if this channel is faulty. Then, of course, this throws an exception if I try to call the service method.I need my client application to either be notified that the service is shutting down, shutting down, or erroneous, or I need to detect it before I call each method of the service.

Does anyone have working examples of this scenario?

+3
source share
2 answers

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
    }
+2
source

I do not think the server can tell the client that it is turned off without the client actually calling the server.

  • If the server is down, it will do nothing
  • If the pipe is closed, it does not need to exchange anything

The best solution I can think of is that you call the catch try and then handle the error when this happens.

0
source

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


All Articles