Ejemplo n.º 1
0
        private object InvokeService(MethodCall methodCall, ProxyOperationRuntime operation)
        {
            object[] outs;
            object[] ins = operation.MapSyncInputs(methodCall, out outs);
            object   ret = _serviceChannel.Call(operation.Action, operation.IsOneWay, operation, ins, outs);

            operation.MapSyncOutputs(methodCall, outs, ref ret);
            return(ret);
        }
Ejemplo n.º 2
0
        IMethodReturnMessage InvokeBeginService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
        {
            AsyncCallback callback;
            object        asyncState;

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

            return(CreateReturnMessage(ret, null, methodCall));
        }
Ejemplo n.º 3
0
            private ProxyOperationRuntime GetOperationByName(string methodName)
            {
                ProxyOperationRuntime op = _runtime.GetOperationByName(methodName);

                if (op == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.Format(SR.SFxMethodNotSupported1, methodName)));
                }
                return(op);
            }
        object SendMessage(OperationDescription opDesc, string action, object[] ins, object[] outs)
        {
            ProxyOperationRuntime operationRuntime = channelBuilderSettings.ServiceChannel.ClientRuntime.GetRuntime().GetOperationByName(opDesc.Name);

            if (operationRuntime == null)
            {
                throw Fx.AssertAndThrow("Operation runtime should not be null");
            }
            return(channelBuilderSettings.ServiceChannel.Call(action, opDesc.IsOneWay, operationRuntime, ins, outs));
        }
Ejemplo n.º 5
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);
        }
            private ProxyOperationRuntime GetOperationByName(string methodName)
            {
                ProxyOperationRuntime operationByName = this.runtime.GetOperationByName(methodName);

                if (operationByName == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(System.ServiceModel.SR.GetString("SFxMethodNotSupported1", new object[] { methodName })));
                }
                return(operationByName);
            }
Ejemplo n.º 7
0
            private System.ServiceModel.Dispatcher.ProxyOperationRuntime GetOperationByName(string methodName)
            {
                ProxyOperationRuntime op = _runtime.GetOperationByName(methodName);

                if (op == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(string.Format(SRServiceModel.SFxMethodNotSupported1, methodName)));
                }
                return(op);
            }
Ejemplo n.º 8
0
        private object InvokeEndService(MethodCall methodCall, ProxyOperationRuntime operation)
        {
            IAsyncResult result;

            object[] outs;
            operation.MapAsyncEndInputs(methodCall, out result, out outs);
            object ret = _serviceChannel.EndCall(operation.Action, outs, result);

            operation.MapAsyncOutputs(methodCall, outs, ref ret);
            return(ret);
        }
        private IMethodReturnMessage InvokeEndService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
        {
            IAsyncResult result;

            object[] objArray;
            operation.MapAsyncEndInputs(methodCall, out result, out objArray);
            object ret = this.serviceChannel.EndCall(operation.Action, objArray, result);

            object[] returnArgs = operation.MapAsyncOutputs(methodCall, objArray, ref ret);
            return(this.CreateReturnMessage(ret, returnArgs, methodCall));
        }
            protected IAsyncResult BeginInvoke(string methodName, object[] args, AsyncCallback callback, object state)
            {
                object[] destinationArray = new object[args.Length + 2];
                Array.Copy(args, destinationArray, args.Length);
                destinationArray[destinationArray.Length - 2] = callback;
                destinationArray[destinationArray.Length - 1] = state;
                IMethodCallMessage    methodCall      = new MethodCallMessage <TChannel, T>(destinationArray);
                ProxyOperationRuntime operationByName = this.GetOperationByName(methodName);

                object[] ins = operationByName.MapAsyncBeginInputs(methodCall, out callback, out state);
                return(this.channel.BeginCall(operationByName.Action, operationByName.IsOneWay, operationByName, ins, callback, state));
            }
Ejemplo n.º 11
0
        private object InvokeService(MethodCall methodCall, ProxyOperationRuntime operation)
        {
            object[] ins = operation.MapSyncInputs(methodCall, out object[] outs);
            object   ret;

            using (TaskHelpers.RunTaskContinuationsOnOurThreads())
            {
                ret = _serviceChannel.CallAsync(operation.Action, operation.IsOneWay, operation, ins, outs).GetAwaiter().GetResult();
            }
            operation.MapSyncOutputs(methodCall, outs, ref ret);
            return(ret);
        }
Ejemplo n.º 12
0
        protected override void Execute(CodeActivityContext context)
        {
            Message inMessage = this.Message.Get(context);

            if (inMessage == null)
            {
                throw FxTrace.Exception.AsError(new InvalidOperationException(SR.NullReplyMessageContractMismatch));
            }
            if (inMessage.IsFault)
            {
                FaultConverter faultConverter = FaultConverter.GetDefaultFaultConverter(inMessage.Version);
                Exception      exception      = DeserializeFault(inMessage, faultConverter);

                // We simply throw the exception
                throw FxTrace.Exception.AsError(exception);
            }
            else
            {
                object[] outObjects;
                if (this.parameters != null)
                {
                    outObjects = new object[this.parameters.Count];
                }
                else
                {
                    outObjects = Constants.EmptyArray;
                }

                object returnValue = this.Formatter.DeserializeReply(inMessage, outObjects);

                if (this.Result != null)
                {
                    this.Result.Set(context, returnValue);
                }

                if (parameters != null)
                {
                    for (int i = 0; i < this.parameters.Count; i++)
                    {
                        OutArgument outArgument = this.parameters[i];
                        Fx.Assert(outArgument != null, "Parameter cannot be null");

                        object obj = outObjects[i];
                        if (obj == null)
                        {
                            obj = ProxyOperationRuntime.GetDefaultParameterValue(outArgument.ArgumentType);
                        }

                        outArgument.Set(context, obj);
                    }
                }
            }
        }
Ejemplo n.º 13
0
            protected IAsyncResult BeginInvoke(string methodName, object[] args, AsyncCallback callback, object state)
            {
                object[] inArgs = new object[args.Length + 2];
                Array.Copy(args, inArgs, args.Length);
                inArgs[inArgs.Length - 2] = callback;
                inArgs[inArgs.Length - 1] = state;

                MethodCall            methodCall = new MethodCall(inArgs);
                ProxyOperationRuntime op         = GetOperationByName(methodName);

                object[] ins = op.MapAsyncBeginInputs(methodCall, out callback, out state);
                return(_channel.BeginCall(op.Action, op.IsOneWay, op, ins, callback, state));
            }
Ejemplo n.º 14
0
            public static Task <T> CreateGenericTask <T>(ServiceChannel channel, ProxyOperationRuntime operation, object[] inputParameters)
            {
                Func <IAsyncResult, T> endCallDelegate = (asyncResult) =>
                {
                    OperationContext originalOperationContext = OperationContext.Current;
                    OperationContext.Current = asyncResult.AsyncState as OperationContext;
                    try
                    {
                        return((T)channel.EndCall(operation.Action, ProxyOperationRuntime.EmptyArray, asyncResult));
                    }
                    finally
                    {
                        OperationContext.Current = originalOperationContext;
                    }
                };

                return(Task <T> .Factory.FromAsync <ServiceChannel, ProxyOperationRuntime, object[]>(beginCallDelegate, endCallDelegate, channel, operation, inputParameters, OperationContext.Current));
            }
Ejemplo n.º 15
0
 protected override void Execute(NativeActivityContext context)
 {
     System.ServiceModel.Channels.Message message = null;
     try
     {
         object[] emptyArray;
         message = this.Message.Get(context);
         if ((this.parameters == null) || (this.parameters.Count == 0))
         {
             emptyArray = System.ServiceModel.Activities.Constants.EmptyArray;
         }
         else
         {
             emptyArray = new object[this.parameters.Count];
         }
         this.Formatter.DeserializeRequest(message, emptyArray);
         if (this.parameters != null)
         {
             for (int i = 0; i < this.parameters.Count; i++)
             {
                 OutArgument argument = this.parameters[i];
                 object      defaultParameterValue = emptyArray[i];
                 if (defaultParameterValue == null)
                 {
                     defaultParameterValue = ProxyOperationRuntime.GetDefaultParameterValue(argument.ArgumentType);
                 }
                 argument.Set(context, defaultParameterValue);
             }
         }
     }
     finally
     {
         if (this.CloseMessage && (message != null))
         {
             message.Close();
         }
         this.Message.Set(context, null);
         System.Activities.NoPersistHandle handle = (this.NoPersistHandle == null) ? null : this.NoPersistHandle.Get(context);
         if (handle != null)
         {
             handle.Exit(context);
         }
     }
 }
            protected object EndInvoke(string methodName, object[] args, IAsyncResult result)
            {
                object[] objArray2;
                object[] destinationArray = new object[args.Length + 1];
                Array.Copy(args, destinationArray, args.Length);
                destinationArray[destinationArray.Length - 1] = result;
                IMethodCallMessage    methodCall      = new MethodCallMessage <TChannel, T>(destinationArray);
                ProxyOperationRuntime operationByName = this.GetOperationByName(methodName);

                operationByName.MapAsyncEndInputs(methodCall, out result, out objArray2);
                object ret = this.channel.EndCall(operationByName.Action, objArray2, result);

                object[] sourceArray = operationByName.MapAsyncOutputs(methodCall, objArray2, ref ret);
                if (sourceArray != null)
                {
                    Array.Copy(sourceArray, args, args.Length);
                }
                return(ret);
            }
Ejemplo n.º 17
0
            static Task CreateTask(ServiceChannel channel, ProxyOperationRuntime operation, object[] inputParameters)
            {
                Action <IAsyncResult> endCallDelegate = (asyncResult) =>
                {
                    Fx.Assert(asyncResult != null, "'asyncResult' MUST NOT be NULL.");
                    OperationContext originalOperationContext = OperationContext.Current;
                    OperationContext.Current = asyncResult.AsyncState as OperationContext;
                    try
                    {
                        channel.EndCall(operation.Action, ProxyOperationRuntime.EmptyArray, asyncResult);
                    }
                    finally
                    {
                        OperationContext.Current = originalOperationContext;
                    }
                };

                return(Task.Factory.FromAsync(beginCallDelegate, endCallDelegate, channel, operation, inputParameters, OperationContext.Current));
            }
        protected override void Execute(CodeActivityContext context)
        {
            object[] emptyArray;
            System.ServiceModel.Channels.Message inMessage = this.Message.Get(context);
            if (inMessage == null)
            {
                throw System.ServiceModel.Activities.FxTrace.Exception.AsError(new InvalidOperationException(System.ServiceModel.Activities.SR.NullReplyMessageContractMismatch));
            }
            if (inMessage.IsFault)
            {
                FaultConverter defaultFaultConverter = FaultConverter.GetDefaultFaultConverter(inMessage.Version);
                Exception      exception             = this.DeserializeFault(inMessage, defaultFaultConverter);
                throw System.ServiceModel.Activities.FxTrace.Exception.AsError(exception);
            }
            if (this.parameters != null)
            {
                emptyArray = new object[this.parameters.Count];
            }
            else
            {
                emptyArray = System.ServiceModel.Activities.Constants.EmptyArray;
            }
            object obj2 = this.Formatter.DeserializeReply(inMessage, emptyArray);

            if (this.Result != null)
            {
                this.Result.Set(context, obj2);
            }
            if (this.parameters != null)
            {
                for (int i = 0; i < this.parameters.Count; i++)
                {
                    OutArgument argument = this.parameters[i];
                    object      defaultParameterValue = emptyArray[i];
                    if (defaultParameterValue == null)
                    {
                        defaultParameterValue = ProxyOperationRuntime.GetDefaultParameterValue(argument.ArgumentType);
                    }
                    argument.Set(context, defaultParameterValue);
                }
            }
        }
Ejemplo n.º 19
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);
            }
Ejemplo n.º 20
0
            protected object EndInvoke(string methodName, object[] args, IAsyncResult result)
            {
                object[] inArgs = new object[args.Length + 1];
                Array.Copy(args, inArgs, args.Length);
                inArgs[inArgs.Length - 1] = result;

                MethodCall            methodCall = new MethodCall(inArgs);
                ProxyOperationRuntime op         = GetOperationByName(methodName);

                object[] outs;
                op.MapAsyncEndInputs(methodCall, out result, out outs);
                object ret = _channel.EndCall(op.Action, outs, result);

                object[] retArgs = op.MapAsyncOutputs(methodCall, outs, ref ret);
                if (retArgs != null)
                {
                    Fx.Assert(retArgs.Length == inArgs.Length, "retArgs.Length should be equal to inArgs.Length");
                    Array.Copy(retArgs, args, args.Length);
                }
                return(ret);
            }
Ejemplo n.º 21
0
            private static Task CreateTask(ServiceChannel channel, ProxyOperationRuntime operation, object[] inputParameters)
            {
                TaskCompletionSource <object> tcs = new TaskCompletionSource <object>();

                Action <Task <object>, object> completeCallDelegate = (antecedent, obj) =>
                {
                    var tcsObj = obj as TaskCompletionSource <object>;
                    Contract.Assert(tcsObj != null);
                    if (antecedent.IsFaulted)
                    {
                        tcsObj.TrySetException(antecedent.Exception.InnerException);
                    }
                    else if (antecedent.IsCanceled)
                    {
                        tcsObj.TrySetCanceled();
                    }
                    else
                    {
                        tcsObj.TrySetResult(antecedent.Result);
                    }
                };


                try
                {
                    channel.CallAsync(operation.Action, operation.IsOneWay, operation, inputParameters,
                                      Array.Empty <object>()).ContinueWith(completeCallDelegate, tcs);
                }
#pragma warning disable CA1031 // Do not catch general exception types - copying all exceptions to TaskCompeletionSource

                catch (Exception e)
                {
                    tcs.TrySetException(e);
                }
#pragma warning restore CA1031 // Do not catch general exception types

                return(tcs.Task);
            }
Ejemplo n.º 22
0
        private MethodData GetMethodData(MethodCall methodCall)
        {
            MethodBase method = methodCall.MethodBase;

            if (_methodDataCache.TryGetMethodData(method, out MethodData methodData))
            {
                return(methodData);
            }

            bool canCacheMessageData;

            Type declaringType = method.DeclaringType;

            if (declaringType == typeof(object) && method == typeof(object).GetMethod("GetType"))
            {
                canCacheMessageData = true;
                methodData          = new MethodData(method, MethodType.GetType);
            }
            else if (declaringType.IsAssignableFrom(_serviceChannel.GetType()))
            {
                canCacheMessageData = true;
                methodData          = new MethodData(method, MethodType.Channel);
            }
            else
            {
                ProxyOperationRuntime operation = _proxyRuntime.GetOperation(method, methodCall.Args, out canCacheMessageData);

                if (operation == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.Format(SR.SFxMethodNotSupportedOnCallback1, method.Name)));
                }

                MethodType methodType;

                if (operation.IsTaskCall(methodCall))
                {
                    methodType = MethodType.TaskService;
                }
                else if (operation.IsSyncCall(methodCall))
                {
                    methodType = MethodType.Service;
                }
                else if (operation.IsBeginCall(methodCall))
                {
                    methodType = MethodType.BeginService;
                }
                else
                {
                    methodType = MethodType.EndService;
                }

                methodData = new MethodData(method, methodType, operation);
            }

            if (canCacheMessageData)
            {
                _methodDataCache.SetMethodData(methodData);
            }

            return(methodData);
        }
Ejemplo n.º 23
0
 public MethodData(MethodBase methodBase, MethodType methodType, ProxyOperationRuntime operation)
 {
     MethodBase = methodBase;
     MethodType = methodType;
     Operation  = operation;
 }
Ejemplo n.º 24
0
        private object InvokeTaskService(MethodCall methodCall, ProxyOperationRuntime operation)
        {
            Task task = TaskCreator.CreateTask(_serviceChannel, methodCall, operation);

            return(task);
        }
Ejemplo n.º 25
0
        MethodData GetMethodData(IMethodCallMessage methodCall)
        {
            MethodBase method = methodCall.MethodBase;

            MethodData methodData;

            if (methodDataCache.TryGetMethodData(method, out methodData))
            {
                return(methodData);
            }

            bool canCacheMessageData;

            Type declaringType = method.DeclaringType;

            if (declaringType == typeof(object))
            {
                MethodType methodType;
                if (methodCall.MethodBase == typeof(object).GetMethod("GetType"))
                {
                    methodType = MethodType.GetType;
                }
                else
                {
                    methodType = MethodType.Object;
                }
                canCacheMessageData = true;
                methodData          = new MethodData(method, methodType);
            }
            else if (declaringType.IsInstanceOfType(this.serviceChannel))
            {
                canCacheMessageData = true;
                methodData          = new MethodData(method, MethodType.Channel);
            }
            else
            {
                ProxyOperationRuntime operation = this.proxyRuntime.GetOperation(method, methodCall.Args, out canCacheMessageData);

                if (operation == null)
                {
                    if (this.serviceChannel.Factory != null)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.GetString(SR.SFxMethodNotSupported1, method.Name)));
                    }
                    else
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.GetString(SR.SFxMethodNotSupportedOnCallback1, method.Name)));
                    }
                }

                MethodType methodType;

                if (operation.IsTaskCall(methodCall))
                {
                    methodType = MethodType.TaskService;
                }
                else if (operation.IsSyncCall(methodCall))
                {
                    methodType = MethodType.Service;
                }
                else if (operation.IsBeginCall(methodCall))
                {
                    methodType = MethodType.BeginService;
                }
                else
                {
                    methodType = MethodType.EndService;
                }

                methodData = new MethodData(method, methodType, operation);
            }

            if (canCacheMessageData)
            {
                methodDataCache.SetMethodData(methodData);
            }

            return(methodData);
        }
Ejemplo n.º 26
0
            static Task CreateGenericTask(ServiceChannel channel, ProxyOperationRuntime operation, object[] inputParameters)
            {
                Func <ServiceChannel, ProxyOperationRuntime, object[], Task> createTaskDelegate = GetOrCreateTaskDelegate(operation.TaskTResult);

                return(createTaskDelegate(channel, operation, inputParameters));
            }
Ejemplo n.º 27
0
        IMessage InvokeTaskService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
        {
            Task task = TaskCreator.CreateTask(this.serviceChannel, methodCall, operation);

            return(CreateReturnMessage(task, null, methodCall));
        }
 public MethodData(System.Reflection.MethodBase methodBase, System.ServiceModel.Channels.ServiceChannelProxy.MethodType methodType, ProxyOperationRuntime operation)
 {
     this.methodBase = methodBase;
     this.methodType = methodType;
     this.operation  = operation;
 }
        private MethodData GetMethodData(IMethodCallMessage methodCall)
        {
            MethodData data;
            MethodBase methodBase = methodCall.MethodBase;

            if (!this.methodDataCache.TryGetMethodData(methodBase, out data))
            {
                bool        flag;
                System.Type declaringType = methodBase.DeclaringType;
                if (declaringType == typeof(object))
                {
                    MethodType getType;
                    if (methodCall.MethodBase == typeof(object).GetMethod("GetType"))
                    {
                        getType = MethodType.GetType;
                    }
                    else
                    {
                        getType = MethodType.Object;
                    }
                    flag = true;
                    data = new MethodData(methodBase, getType);
                }
                else if (declaringType.IsInstanceOfType(this.serviceChannel))
                {
                    flag = true;
                    data = new MethodData(methodBase, MethodType.Channel);
                }
                else
                {
                    MethodType            service;
                    ProxyOperationRuntime operation = this.proxyRuntime.GetOperation(methodBase, methodCall.Args, out flag);
                    if (operation == null)
                    {
                        if (this.serviceChannel.Factory != null)
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(System.ServiceModel.SR.GetString("SFxMethodNotSupported1", new object[] { methodBase.Name })));
                        }
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(System.ServiceModel.SR.GetString("SFxMethodNotSupportedOnCallback1", new object[] { methodBase.Name })));
                    }
                    if (operation.IsSyncCall(methodCall))
                    {
                        service = MethodType.Service;
                    }
                    else if (operation.IsBeginCall(methodCall))
                    {
                        service = MethodType.BeginService;
                    }
                    else
                    {
                        service = MethodType.EndService;
                    }
                    data = new MethodData(methodBase, service, operation);
                }
                if (flag)
                {
                    this.methodDataCache.SetMethodData(data);
                }
            }
            return(data);
        }
Ejemplo n.º 30
0
 public static Task CreateTask(ServiceChannel channel, MethodCall methodCall, ProxyOperationRuntime operation)
 {
     if (operation.TaskTResult == ServiceReflector.VoidType)
     {
         return(CreateTask(channel, operation, methodCall.Args));
     }
     return(CreateGenericTask(channel, operation, methodCall.Args));
 }