2

I've added Connected Service (WCF Client) into .NET Standard 2.0 project.

I'm trying to setup the wcf binding so that when there is Communication Exception, it will retry the request. Something like https://stackoverflow.com/a/1968874/475727

How do I do it in .NET Standard 2.0?

Liero
  • 25,216
  • 29
  • 151
  • 297

1 Answers1

1

Reliable Sessions are not yet supported in .NET Core. You are basically on your own on this in the sense that you'll need to implement the business logic behind this. Maybe this helps you:

public static void Retry(int retryCount, TimeSpan delay, Action action)
    {
        bool b = Retry<bool>(
            retryCount,
            delay,
            () => { action(); return true; });
    }

    public static T Retry<T>(int retryCount, TimeSpan delay, Func<T> func)
    {
        int currentAttempt = 0;

        while (true)
        {
            try
            {
                ++currentAttempt;
                return func();
            }
            catch
            {
                if (currentAttempt == retryCount)
                {
                    throw;
                }
            }

            if (delay > TimeSpan.Zero)
            {
                Thread.Sleep(delay);
            }
        }
    }
Jorge Del Conde
  • 265
  • 1
  • 4