I am not sure if this is the good practice and correct usage of API, but I would implement this using Channel instance of your client. So in client class I would expose IsReady method for trying to connect and checking the state of the channel afterwards. Here is a code example:
public bool IsReady()
{
channel.ConnectAsync();
return channel.State == ChannelState.Ready;
}
You can also implement async version of this method with passing deadline for connection:
public async Task<bool> IsReadyAsync(DateTime? deadline)
{
try
{
await channel.ConnectAsync(deadline: deadline);
}
catch (TaskCanceledException)
{
return false;
}
return channel.State == ChannelState.Ready;
}
ConnectAsync method requests channel to connect service without starting an RPC. Returned task completes once channel state is Ready. If the deadline is reached, or channel enters the Shutdown state, the task is cancelled. So you can play around with this to achieve your goal or use examples provided if they will work for you.