Esempio n. 1
0
        public void Sample3_Level300_AutomaticRetry_StaticServiceConsumerRetryPolicy_UsingMicrosoftTransientFaultHandling_WithConsumeMethod()
        {
            var microsoftRetryStrategy = new Incremental(5, TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(2));
            var microsoftRetryPolicy   = new RetryPolicy <SoapFaultWebServiceTransientErrorDetectionStrategy>(microsoftRetryStrategy);

            ServiceConsumerFactory.DefaultRetryPolicy = microsoftRetryPolicy.ForServiceConsumer(); // extension method
            // or ServiceConsumerFactory.DefaultRetryPolicy = new ChannelAdam.TransientFaultHandling.RetryPolicyAdapter(microsoftRetryPolicy);
            // or ServiceConsumerFactory.DefaultRetryPolicy = (ChannelAdam.TransientFaultHandling.IRetryPolicyFunction)microsoftRetryPolicy;

            using (var service = ServiceConsumerFactory.Create <IFakeService>(() => new FakeServiceClient()))
            {
                var result = service.Consume(operation => operation.AddIntegers(1, 1));

                if (result.HasNoException)
                {
                    Console.WriteLine("Actual: " + result.Value);
                    Assert.AreEqual(2, result.Value);
                }
                else
                {
                    if (result.HasFaultException)
                    {
                        Console.WriteLine("Service operation threw a fault: " + result.Exception.ToString());
                    }
                    else if (result.HasException)
                    {
                        Console.WriteLine("Technical error occurred while calling the service operation: " + result.Exception.ToString());
                    }

                    Assert.Fail("Service operation was not successfully called");
                }
            }
        }
Esempio n. 2
0
        public void Sample3_Level300_AutomaticRetry_ServiceConsumerRetryPolicy_UsingMicrosoftTransientFaultHandling_UsingOperationsProperty()
        {
            var microsoftRetryStrategy = new Incremental(5, TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(2));
            var microsoftRetryPolicy   = new RetryPolicy <SoapFaultWebServiceTransientErrorDetectionStrategy>(microsoftRetryStrategy);

            var serviceConsumerRetryPolicy = microsoftRetryPolicy.ForServiceConsumer(); // extension method

            // or var serviceConsumerRetryPolicy = new ChannelAdam.TransientFaultHandling.RetryPolicyAdapter(microsoftRetryPolicy);
            // or var serviceConsumerRetryPolicy = (ChannelAdam.TransientFaultHandling.IRetryPolicyFunction)microsoftRetryPolicy;
            using (var service = ServiceConsumerFactory.Create <IFakeService>(() => new FakeServiceClient(), serviceConsumerRetryPolicy))
            {
                try
                {
                    int actual = service.Operations.AddIntegers(1, 1);

                    Console.WriteLine("Actual: " + actual);
                    Assert.AreEqual(2, actual);

                    return;
                }
                catch (FaultException fe)
                {
                    Console.WriteLine("Service operation threw a fault: " + fe.ToString());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Technical error occurred while calling the service operation: " + ex.ToString());
                }

                Assert.Fail("Service operation was not successfully called");
            }
        }