コード例 #1
0
        // } 2017/03/01

        public static CalcErrorCode  Execute(Action <CalcClient> act)
        {
            CalcErrorCode errorCode = CalcErrorCode.None;

            try
            {
                if (client == null)
                {
                    Open(serverUri);
                }

                act(client);
                errorCode = CalcErrorCode.None;
            }
            catch (System.ServiceModel.CommunicationException ex)
            {
                client.Abort();
                client    = null;
                errorCode = CalcErrorCode.CommunicationWithServerError;
                OnFatalError();
                Console.WriteLine("WCF communication error happened.");
                Console.WriteLine(ex);
            }
            catch (TimeoutException)
            {
                client.Abort();
                client    = null;
                errorCode = CalcErrorCode.CommunicationWithServerError;
                Console.WriteLine("WCF timeout happened.");
            }
            catch (DivideByZeroException ex)
            {
                client    = null;
                errorCode = CalcErrorCode.DivideByZero;
                OnFatalError();
                Console.WriteLine(ex);
            }
            return(errorCode);
        }