Example #1
0
        public void ThrowException(WCFInvocationMethod clientInvocationMethod, WCFInvocationMethod serviceInvocationMethod, bool asyncThrowOnBegin)
        {
            if (_wcfClient == null)
            {
                throw new InvalidOperationException("WCF Client not instantiated");
            }

            if (_needToPauseForWarmup)
            {
                PauseForWarmup();
            }

            try
            {
                string result = null;
                switch (clientInvocationMethod)
                {
                case WCFInvocationMethod.Sync:
                    switch (serviceInvocationMethod)
                    {
                    case WCFInvocationMethod.Sync:
                        result = _wcfClient.Sync_SyncThrowException();
                        break;

                    case WCFInvocationMethod.BeginEndAsync:
                        result = asyncThrowOnBegin
                                    ? _wcfClient.Sync_AsyncThrowExceptionAtStart()
                                    : _wcfClient.Sync_AsyncThrowExceptionAtEnd();
                        break;

                    case WCFInvocationMethod.TAPAsync:
                        result = _wcfClient.Sync_TAPThrowException();
                        break;

                    default:
                        throw new NotImplementedException($"Client/Service Invocation Method Combo {clientInvocationMethod}/{serviceInvocationMethod}");
                    }
                    break;

                case WCFInvocationMethod.BeginEndAsync:
                    switch (serviceInvocationMethod)
                    {
                    case WCFInvocationMethod.Sync:
                    {
                        var asyncResult = _wcfClient.Begin_SyncThrowException(null, null);
                        result = _wcfClient.End_SyncThrowException(asyncResult);
                    }
                    break;

                    case WCFInvocationMethod.BeginEndAsync:
                    {
                        if (asyncThrowOnBegin)
                        {
                            var asyncResult = _wcfClient.Begin_AsyncThrowExceptionAtStart(null, null);
                            result = _wcfClient.End_AsyncThrowExceptionAtStart(asyncResult);
                        }
                        else
                        {
                            var asyncResult = _wcfClient.Begin_AsyncThrowExceptionAtEnd(null, null);
                            result = _wcfClient.End_AsyncThrowExceptionAtEnd(asyncResult);
                        }
                    }
                    break;

                    case WCFInvocationMethod.TAPAsync:
                    {
                        var asyncResult = _wcfClient.Begin_TAPThrowException(null, null);
                        result = _wcfClient.End_TAPThrowException(asyncResult);
                    }
                    break;

                    default:
                        throw new NotImplementedException($"Client/Service Invocation Method Combo {clientInvocationMethod}/{serviceInvocationMethod}");
                    }

                    break;

                case WCFInvocationMethod.TAPAsync:
                    switch (serviceInvocationMethod)
                    {
                    case WCFInvocationMethod.Sync:
                    {
                        result = _wcfClient.TAP_SyncThrowException().Result;
                    }
                    break;

                    case WCFInvocationMethod.BeginEndAsync:
                    {
                        result = asyncThrowOnBegin
                                        ? _wcfClient.TAP_AsyncThrowExceptionAtStart().Result
                                        : _wcfClient.TAP_AsyncThrowExceptionAtEnd().Result;
                    }
                    break;

                    case WCFInvocationMethod.TAPAsync:
                    {
                        result = _wcfClient.TAP_TAPThrowException().Result;
                    }
                    break;

                    default:
                        throw new NotImplementedException($"Client/Service Invocation Method Combo {clientInvocationMethod}/{serviceInvocationMethod}");
                    }
                    break;

                case WCFInvocationMethod.EventBasedAsync:
                    switch (serviceInvocationMethod)
                    {
                    case WCFInvocationMethod.Sync:
                        using (var wait = new ManualResetEvent(false))
                        {
                            _wcfClient.Event_ThrowException_Completed += (e, a) =>
                            {
                                if (a.Error != null)
                                {
                                    result = "Handled Expected WCF Exception";
                                }
                                else
                                {
                                    throw new Exception("Expected WCF Error didn't occur");
                                }

                                wait.Set();
                            };
                            _wcfClient.Event_SyncThrowException();
                            wait.WaitOne(TimeSpan.FromSeconds(20));
                        }
                        break;

                    default:
                        throw new NotImplementedException($"Client/Service Invocation Method Combo {clientInvocationMethod}/{serviceInvocationMethod}");
                    }
                    break;

                default:
                    throw new NotImplementedException($"Client Invocation Method {clientInvocationMethod} Not supported");
                }

                Logger.Info($"Result: {result ?? "<NULL>"}");
            }
            catch (FaultException)

            {
                Logger.Info("Ignoring WCF Fault Exception!");
            }
            catch (AggregateException aggEx)
            {
                if (!(aggEx.InnerException is FaultException) && !(aggEx.InnerException is ProtocolException))
                {
                    throw;
                }

                Logger.Info($"Ignoring AggregateException -> WCF {aggEx.InnerException.GetType()} Exception!");
            }
            catch (TargetInvocationException tgtEx)
            {
                if (!(tgtEx.InnerException is FaultException <ExceptionDetail>))
                {
                    throw;
                }


                Logger.Info("Ignoring TergetInvocationException -> WCF Fault Exception<ExceptionDetail>!");
            }
            catch (ProtocolException)
            {
                Logger.Info("Ignoring ProtocolException");
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
        }
Example #2
0
        public void GetData(WCFInvocationMethod clientInvocationMethod, WCFInvocationMethod serviceInvocationMethod, int value)
        {
            if (_wcfClient == null)
            {
                throw new InvalidOperationException("WCF Client not instantiated");
            }

            if (_needToPauseForWarmup)
            {
                PauseForWarmup();
            }

            string result = null;

            switch (clientInvocationMethod)
            {
            case WCFInvocationMethod.Sync:
                switch (serviceInvocationMethod)
                {
                case WCFInvocationMethod.Sync:
                    result = _wcfClient.Sync_SyncGetData(value);
                    break;

                case WCFInvocationMethod.BeginEndAsync:
                    result = _wcfClient.Sync_AsyncGetData(value);
                    break;

                case WCFInvocationMethod.TAPAsync:
                    result = _wcfClient.Sync_TAPGetData(value);
                    break;

                default:
                    throw new NotImplementedException($"Client/Service Invocation Method Combo {clientInvocationMethod}/{serviceInvocationMethod}");
                }
                break;

            case WCFInvocationMethod.BeginEndAsync:
                switch (serviceInvocationMethod)
                {
                case WCFInvocationMethod.Sync:
                {
                    var asyncResult = _wcfClient.Begin_SyncGetData(value, null, null);
                    result = _wcfClient.End_SyncGetData(asyncResult);
                }
                break;

                case WCFInvocationMethod.BeginEndAsync:
                {
                    var asyncResult = _wcfClient.Begin_AsyncGetData(value, null, null);
                    result = _wcfClient.End_AsyncGetData(asyncResult);
                }
                break;

                case WCFInvocationMethod.TAPAsync:
                {
                    var asyncResult = _wcfClient.Begin_TAPGetData(value, null, null);
                    result = _wcfClient.End_TAPGetData(asyncResult);
                }
                break;

                default:
                    throw new NotImplementedException($"Client/Service Invocation Method Combo {clientInvocationMethod}/{serviceInvocationMethod}");
                }
                break;

            case WCFInvocationMethod.TAPAsync:
                switch (serviceInvocationMethod)
                {
                case WCFInvocationMethod.Sync:
                {
                    result = _wcfClient.TAP_SyncGetData(value).Result;
                }
                break;

                case WCFInvocationMethod.BeginEndAsync:
                {
                    result = _wcfClient.TAP_AsyncGetData(value).Result;
                }
                break;

                case WCFInvocationMethod.TAPAsync:
                {
                    result = _wcfClient.TAP_TAPGetData(value).Result;
                }
                break;

                default:
                    throw new NotImplementedException($"Client/Service Invocation Method Combo {clientInvocationMethod}/{serviceInvocationMethod}");
                }
                break;

            case WCFInvocationMethod.EventBasedAsync:
                switch (serviceInvocationMethod)
                {
                case WCFInvocationMethod.Sync:
                {
                    using (var wait = new ManualResetEvent(false))
                    {
                        _wcfClient.Event_SyncGetData_Completed += (e, a) =>
                        {
                            result = a.Result;
                            wait.Set();
                        };
                        _wcfClient.Event_SyncGetData(32);
                        wait.WaitOne(TimeSpan.FromSeconds(20));
                    }
                }
                break;

                default:
                    throw new NotImplementedException($"Client/Service Invocation Method Combo {clientInvocationMethod}/{serviceInvocationMethod}");
                }
                break;

            default:
                throw new NotImplementedException($"Client Invocation Method {clientInvocationMethod} Not supported");
            }

            Logger.Info($"Result: {result ?? "<NULL>"}");
        }