1

I've looked at a bunch of threads like Detect if wcf service is activated but these solutions require the client to proactively detect if the WCF service is running. But what if I am in the middle of a transaction and the WCF service goes down or the connection is lost for some reason? In my testing there is no exception thrown; either nothing happens at all or that twirly circle thing just keeps going round and round. I want the client to detect if the service/connection is lost and gracefully tell the user it's down. I have timeouts set in my code:

NetNamedPipeBinding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
            binding.OpenTimeout = TimeSpan.FromSeconds(15);
            binding.SendTimeout = TimeSpan.FromSeconds(3000);
            binding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
            this._engineChannel = new DuplexChannelFactory<IEngineApi>(this, binding, new EndpointAddress("net.pipe://localhost/Engine"));

But if I am in the middle of a transaction nothing actually happens; these timeouts don't seem to affect anything.

Community
  • 1
  • 1
  • 2
    might be good info here: http://stackoverflow.com/questions/340521/how-can-i-make-named-pipe-binding-reconnect-automatically-in-wcf – Daniel A. White Jul 24 '15 at 15:54

1 Answers1

2

You can use one of the two approaches:

1

The two things I do are a telnet check to make sure the WCF process has the socket open.

telnet host 8080 The second thing I do is always add an IsAlive method to my WCF contract so that there is a simple method to call to check that the service host is operating correctly.

public bool IsAlive() { return true; }

Source: Pinging WCF Services

2

Use the Discovery/Announcement feature introduced in WCF 4.0

Discovery depends on the User Datagram Protocol (UDP). UDP is a connectionless protocol, and there is no direct connection required between the client and server. The client usages UDP to broadcast finding requests for any endpoint supporting a specified contract type. The discovery endpoints that support this contract will receive the request. The implementation of the discovery endpoint responds back to the client with the address of the service endpoints. Once the client determines the services, it invokes the service to set up call.

Simple usage example: http://www.codeproject.com/Articles/469549/WCF-Discovery

DeJaVo
  • 3,091
  • 2
  • 17
  • 32