コード例 #1
0
 public static void Close()
 {
     try
     {
         client.Close();
         client = null;
     }
     catch (System.ServiceModel.CommunicationException)
     {
         client.Abort();
         client = null;
         Console.WriteLine("WCF communication error happened.");
     }
     catch (TimeoutException)
     {
         client.Abort();
         client = null;
         Console.WriteLine("WCF timeout happened.");
     }
     catch (Exception ex)
     {
         client = null;
         Console.WriteLine(ex);
     }
 }
コード例 #2
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);
        }