private static void OnAsyncCallCompleted(IAsyncResult result)
 {
     if (!result.CompletedSynchronously)
     {
         AsyncOperationContext <TChannel> asyncState = (AsyncOperationContext <TChannel>)result.AsyncState;
         Exception error   = null;
         object[]  results = null;
         try
         {
             results = asyncState.EndDelegate(result);
         }
         catch (Exception exception2)
         {
             if (Fx.IsFatal(exception2))
             {
                 throw;
             }
             error = exception2;
         }
         ClientBase <TChannel> .CompleteAsyncCall(asyncState, results, error);
     }
 }
        protected void InvokeAsync(BeginOperationDelegate <TChannel> beginOperationDelegate, object[] inValues, EndOperationDelegate <TChannel> endOperationDelegate, SendOrPostCallback operationCompletedCallback, object userState)
        {
            if (beginOperationDelegate == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("beginOperationDelegate");
            }
            if (endOperationDelegate == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("endOperationDelegate");
            }
            AsyncOperationContext <TChannel> state = new AsyncOperationContext <TChannel>(AsyncOperationManager.CreateOperation(userState), endOperationDelegate, operationCompletedCallback);
            Exception error = null;

            object[]     results = null;
            IAsyncResult result  = null;

            try
            {
                result = beginOperationDelegate(inValues, ClientBase <TChannel> .onAsyncCallCompleted, state);
                if (result.CompletedSynchronously)
                {
                    results = endOperationDelegate(result);
                }
            }
            catch (Exception exception2)
            {
                if (Fx.IsFatal(exception2))
                {
                    throw;
                }
                error = exception2;
            }
            if ((error != null) || result.CompletedSynchronously)
            {
                ClientBase <TChannel> .CompleteAsyncCall(state, results, error);
            }
        }