当前位置: 首页>>代码示例>>C#>>正文


C# CalculatorClient.Abort方法代码示例

本文整理汇总了C#中CalculatorClient.Abort方法的典型用法代码示例。如果您正苦于以下问题:C# CalculatorClient.Abort方法的具体用法?C# CalculatorClient.Abort怎么用?C# CalculatorClient.Abort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CalculatorClient的用法示例。


在下文中一共展示了CalculatorClient.Abort方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main()
        {
            // Create a client with Certificate endpoint configuration
            CalculatorClient client = new CalculatorClient("Certificate");

            try
            {
                client.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.CurrentUser, StoreName.My, X509FindType.FindBySubjectName, "alice");

                // Call the Add service operation.
                double value1 = 100.00D;
                double value2 = 15.99D;
                double result = client.Add(value1, value2);
                Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

                // Call the Subtract service operation.
                value1 = 145.00D;
                value2 = 76.54D;
                result = client.Subtract(value1, value2);
                Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);

                // Call the Multiply service operation.
                value1 = 9.00D;
                value2 = 81.25D;
                result = client.Multiply(value1, value2);
                Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);

                // Call the Divide service operation.
                value1 = 22.00D;
                value2 = 7.00D;
                result = client.Divide(value1, value2);
                Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);
                client.Close();
            }
            catch (TimeoutException e)
            {
                Console.WriteLine("Call timed out : {0}", e.Message);
                client.Abort();
            }
            catch (CommunicationException e)
            {
                Console.WriteLine("Call failed : {0}", e.Message);
                client.Abort();
            }
            catch (Exception e)
            {
                Console.WriteLine("Call failed : {0}", e.Message);
                client.Abort();
            }

            

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
开发者ID:ssickles,项目名称:archive,代码行数:56,代码来源:client.cs

示例2: Main

        static void Main()
        {
            // Create a client with given client endpoint configuration
            CalculatorClient client = new CalculatorClient();

            try
            {
                // Call the Add service operation.
                int value1 = 15;
                int value2 = 3;
                int result = client.Add(value1, value2);
                Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

                // Call the Subtract service operation.
                value1 = 145;
                value2 = 76;
                result = client.Subtract(value1, value2);
                Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);

                // Call the Multiply service operation.
                value1 = 9;
                value2 = 81;
                result = client.Multiply(value1, value2);
                Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);

                // Call the Divide service operation - trigger a divide by zero error.
                value1 = 22;
                value2 = 0;
                result = client.Divide(value1, value2);
                Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);

                //Closing the client gracefully closes the connection and cleans up resources
                client.Close();
            }
            catch (FaultException<MathFault> e)
            {
                Console.WriteLine("FaultException<MathFault>: Math fault while doing " + e.Detail.Operation + ". Problem: " + e.Detail.ProblemType);
                client.Abort();
            }
            catch (FaultException e)
            {
                Console.WriteLine("Unknown FaultException: " + e.GetType().Name + " - " + e.Message);
                client.Abort();
            }
            catch (Exception e)
            {
                Console.WriteLine("EXCEPTION: " + e.GetType().Name + " - " + e.Message);
                client.Abort();
            }

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
开发者ID:tian1ll1,项目名称:WPF_Examples,代码行数:54,代码来源:client.cs

示例3: DemonstrateCommunicationException

        static void DemonstrateCommunicationException()
        {
            // Create a client
            CalculatorClient client = new CalculatorClient();

            try
            {
                // Call the Add service operation.
                double value1 = 100.00D;
                double value2 = 15.99D;
                double result = client.Add(value1, value2);
                Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

                // Simulate a network problem by aborting the connection.
                Console.WriteLine("Simulated network problem occurs...");
                client.Abort();

                // Call the Divide service operation.  Now that the channel has been
                // abruptly terminated, the next call will fail.
                value1 = 22.00D;
                value2 = 7.00D;
                result = client.Divide(value1, value2);
                Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);

                // SHOULD NOT GET HERE -- Divide should throw

                // If we had gotten here, we would want to close the client gracefully so
                // that the channel closes gracefully and cleans up resources.
                client.Close();

                Console.WriteLine("Service successfully returned all results.");
            }
            catch (TimeoutException exception)
            {
                Console.WriteLine("Got {0}", exception.GetType());
                client.Abort();
            }
            catch (CommunicationException exception)
            {
                // Control comes here when client.Divide throws.  The actual Exception
                // type is CommunicationObjectAbortedException, which is a subclass of
                // CommunicationException.
                Console.WriteLine("Got {0}", exception.GetType());
                client.Abort();
            }
        }
开发者ID:tian1ll1,项目名称:WPF_Examples,代码行数:46,代码来源:client.cs

示例4: DemonstrateCleanupWithExceptions

        // This method shows the correct way to clean up a client, including catching the
        // approprate Exceptions.
        static void DemonstrateCleanupWithExceptions()
        {
            // Create a client
            CalculatorClient client = new CalculatorClient();
            try
            {
                // Demonstrate a successful client call.
                Console.WriteLine("Calling client.Add(0.0, 0.0);");
                double addValue = client.Add(0.0, 0.0);
                Console.WriteLine("        client.Add(0.0, 0.0); returned {0}", addValue);

                // Demonstrate a failed client call.
                Console.WriteLine("Calling client.Divide(0.0, 0.0);");
                double divideValue = client.Divide(0.0, 0.0);
                Console.WriteLine("        client.Divide(0.0, 0.0); returned {0}", divideValue);

                // Do a clean shutdown if everything works.  In this sample we do not end up
                // here, but correct code should Close the client if everything was successful.
                Console.WriteLine("Closing the client");
                client.Close();
            }
            catch (CommunicationException e)
            {
                // Because the server suffered an internal server error, it rudely terminated
                // our connection, so we get a CommunicationException.
                Console.WriteLine("Got {0} from Divide.", e.GetType());
                client.Abort();
            }
            catch (TimeoutException e)
            {
                // In this sample we do not end up here, but correct code should catch
                // TimeoutException when calling a client.
                Console.WriteLine("Got {0} from Divide.", e.GetType());
                client.Abort();
            }
            catch (Exception e)
            {
                // In this sample we do not end up here.  It is best practice to clean up the
                // client if some unexpected Exception occurs.
                Console.WriteLine("Got unexpected {0} from Divide, rethrowing.", e.GetType());
                client.Abort();
                throw;
            }
        }
开发者ID:XyPis,项目名称:Xy.Pis.Framework-RC,代码行数:46,代码来源:UsingUsing.cs

示例5: DemonstrateTimeoutException

        static void DemonstrateTimeoutException()
        {
            // Create a client
            CalculatorClient client = new CalculatorClient();

            try
            {
                // Call the Add service operation.
                double value1 = 100.00D;
                double value2 = 15.99D;
                double result = client.Add(value1, value2);
                Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

                // Set a ridiculously small timeout.  This will cause the next call to
                // fail with a TimeoutException because it cannot process in time.
                Console.WriteLine("Set timeout too short for method to complete...");
                client.InnerChannel.OperationTimeout = TimeSpan.FromMilliseconds(0.001);

                // Call the Divide service operation.
                value1 = 22.00D;
                value2 = 7.00D;
                result = client.Divide(value1, value2);
                Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);

                // SHOULD NOT GET HERE -- Divide should throw

                // If we had gotten here, we would want to close the client gracefully so
                // that the channel closes gracefully and cleans up resources.
                client.Close();

                Console.WriteLine("Service successfully returned all results.");
            }
            catch (TimeoutException exception)
            {
                // Control comes here when client.Divide throws a TimeoutException.
                Console.WriteLine("Got {0}", exception.GetType());
                client.Abort();
            }
            catch (CommunicationException exception)
            {
                Console.WriteLine("Got {0}", exception.GetType());
                client.Abort();
            }
        }
开发者ID:tian1ll1,项目名称:WPF_Examples,代码行数:44,代码来源:client.cs


注:本文中的CalculatorClient.Abort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。