Exemplo n.º 1
0
        private object InvokeBeginService(MethodCall methodCall, ProxyOperationRuntime operation)
        {
            AsyncCallback callback;
            object        asyncState;

            object[] ins = operation.MapAsyncBeginInputs(methodCall, out callback, out asyncState);
            object   ret = _serviceChannel.BeginCall(operation.Action, operation.IsOneWay, operation, ins, callback, asyncState);

            return(ret);
        }
Exemplo n.º 2
0
            private static Task CreateTask(ServiceChannel channel, ProxyOperationRuntime operation, object[] inputParameters)
            {
                TaskCompletionSource <object> tcs = new TaskCompletionSource <object>();
                bool completedCallback            = false;

                Action <IAsyncResult> endCallDelegate = (asyncResult) =>
                {
                    Contract.Assert(asyncResult != null, "'asyncResult' MUST NOT be NULL.");
                    completedCallback = true;
                    OperationContext originalOperationContext = OperationContext.Current;
                    OperationContext.Current = asyncResult.AsyncState as OperationContext;
                    try
                    {
                        channel.EndCall(operation.Action, Array.Empty <object>(), asyncResult);
                        tcs.TrySetResult(null);
                    }
                    catch (Exception e)
                    {
                        tcs.TrySetException(e);
                    }
                    finally
                    {
                        OperationContext.Current = originalOperationContext;
                    }
                };

                try
                {
                    IAsyncResult ar = ServiceChannel.BeginCall(channel, operation, inputParameters, new AsyncCallback(endCallDelegate), OperationContext.Current);
                    if (ar.CompletedSynchronously && !completedCallback)
                    {
                        endCallDelegate(ar);
                    }
                }
                catch (Exception e)
                {
                    tcs.TrySetException(e);
                }

                return(tcs.Task);
            }