//readonly bool isInsideTransactedReceiveScope;

        internal DispatchOperationRuntime(DispatchOperation operation, ImmutableDispatchRuntime parent)
        {
            if (operation == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(operation));
            }
            if (parent == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(parent));
            }
            if (operation.Invoker == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.RuntimeRequiresInvoker0));
            }

            disposeParameters       = ((operation.AutoDisposeParameters) && (!operation.HasNoDisposableParameters));
            this.parent             = parent;
            callContextInitializers = EmptyArray <ICallContextInitializer> .ToArray(operation.CallContextInitializers);

            inspectors = EmptyArray <IParameterInspector> .ToArray(operation.ParameterInspectors);

            faultFormatter     = operation.FaultFormatter;
            impersonation      = operation.Impersonation;
            deserializeRequest = operation.DeserializeRequest;
            serializeReply     = operation.SerializeReply;
            formatter          = operation.Formatter;
            invoker            = operation.Invoker;

            try
            {
                isSynchronous = operation.Invoker.IsSynchronous;
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(e);
            }
            isTerminating = operation.IsTerminating;
            isSessionOpenNotificationEnabled = operation.IsSessionOpenNotificationEnabled;
            action = operation.Action;
            name   = operation.Name;
            releaseInstanceAfterCall  = operation.ReleaseInstanceAfterCall;
            releaseInstanceBeforeCall = operation.ReleaseInstanceBeforeCall;
            replyAction = operation.ReplyAction;
            isOneWay    = operation.IsOneWay;
            //this.transactionAutoComplete = operation.TransactionAutoComplete;
            //this.transactionRequired = operation.TransactionRequired;
            receiveContextAcknowledgementMode = operation.ReceiveContextAcknowledgementMode;
            bufferedReceiveEnabled            = operation.BufferedReceiveEnabled;
            //this.isInsideTransactedReceiveScope = operation.IsInsideTransactedReceiveScope;

            if (formatter == null && (deserializeRequest || serializeReply))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.DispatchRuntimeRequiresFormatter0, name)));
            }

            if ((operation.Parent.InstanceProvider == null) && (operation.Parent.Type != null))
            {
                SyncMethodInvoker sync = invoker as SyncMethodInvoker;
                if (sync != null)
                {
                    ValidateInstanceType(operation.Parent.Type, sync.Method);
                }

                //AsyncMethodInvoker async = this.invoker as AsyncMethodInvoker;
                //if (async != null)
                //{
                //    this.ValidateInstanceType(operation.Parent.Type, async.BeginMethod);
                //    this.ValidateInstanceType(operation.Parent.Type, async.EndMethod);
                //}

                TaskMethodInvoker task = invoker as TaskMethodInvoker;
                if (task != null)
                {
                    ValidateInstanceType(operation.Parent.Type, task.TaskMethod);
                }
            }
        }
Exemple #2
0
        void IOperationBehavior.ApplyDispatchBehavior(OperationDescription description, DispatchOperation dispatch)
        {
            if (dispatch == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(dispatch));
            }
            if (description == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(description));
            }

            if (description.TaskMethod != null)
            {
                dispatch.Invoker = new TaskMethodInvoker(description.TaskMethod, description.TaskTResult);
            }
            else if (description.SyncMethod != null)
            {
                if (description.BeginMethod != null)
                {
                    // both sync and async methods are present on the contract, check the preference
                    //OperationBehaviorAttribute operationBehaviorAttribute = description.Behaviors.Find<OperationBehaviorAttribute>();
                    //if ((operationBehaviorAttribute != null) && operationBehaviorAttribute.PreferAsyncInvocation)
                    //{
                    //    dispatch.Invoker = new AsyncMethodInvoker(description.BeginMethod, description.EndMethod);
                    //}
                    //else
                    //{
                    dispatch.Invoker = new SyncMethodInvoker(description.SyncMethod);
                    //}
                }
                else
                {
                    // only sync method is present on the contract
                    dispatch.Invoker = new SyncMethodInvoker(description.SyncMethod);
                }
            }
            else
            {
                if (description.BeginMethod != null)
                {
                    // only async method is present on the contract
                    throw new PlatformNotSupportedException();
                    //dispatch.Invoker = new AsyncMethodInvoker(description.BeginMethod, description.EndMethod);
                }
            }
        }
        //bool didTraceProcessMessage1 = false;
        //bool didTraceProcessMessage2 = false;
        //bool didTraceProcessMessage3 = false;
        //bool didTraceProcessMessage31 = false;
        //bool didTraceProcessMessage4 = false;
        //bool didTraceProcessMessage41 = false;

        internal ImmutableDispatchRuntime(DispatchRuntime dispatch)
        {
            //this.authenticationBehavior = AuthenticationBehavior.TryCreate(dispatch);
            //this.authorizationBehavior = AuthorizationBehavior.TryCreate(dispatch);
            concurrency  = new ConcurrencyBehavior(dispatch);
            error        = new ErrorBehavior(dispatch.ChannelDispatcher);
            enableFaults = dispatch.EnableFaults;
            inputSessionShutdownHandlers = EmptyArray <IInputSessionShutdown> .ToArray(dispatch.InputSessionShutdownHandlers);

            instance          = new InstanceBehavior(dispatch, this);
            isOnServer        = dispatch.IsOnServer;
            manualAddressing  = dispatch.ManualAddressing;
            messageInspectors = EmptyArray <IDispatchMessageInspector> .ToArray(dispatch.MessageInspectors);

            //this.requestReplyCorrelator = new RequestReplyCorrelator();
            //this.securityImpersonation = SecurityImpersonationBehavior.CreateIfNecessary(dispatch);
            //this.RequireClaimsPrincipalOnOperationContext = dispatch.RequireClaimsPrincipalOnOperationContext;
            //this.impersonateOnSerializingReply = dispatch.ImpersonateOnSerializingReply;
            terminate = TerminatingOperationBehavior.CreateIfNecessary(dispatch);
            thread    = new ThreadBehavior(dispatch);
            ValidateMustUnderstand = dispatch.ValidateMustUnderstand;
            //this.ignoreTransactionFlow = dispatch.IgnoreTransactionMessageProperty;
            //this.transaction = TransactionBehavior.CreateIfNeeded(dispatch);
            //sendAsynchronously = dispatch.ChannelDispatcher.SendAsynchronously;
            ParameterInspectorCorrelationOffset = (dispatch.MessageInspectors.Count +
                                                   dispatch.MaxCallContextInitializers);
            correlationCount = ParameterInspectorCorrelationOffset + dispatch.MaxParameterInspectors;

            DispatchOperationRuntime unhandled = new DispatchOperationRuntime(dispatch.UnhandledDispatchOperation, this);

            if (dispatch.OperationSelector == null)
            {
                ActionDemuxer demuxer = new ActionDemuxer();
                for (int i = 0; i < dispatch.Operations.Count; i++)
                {
                    DispatchOperation        operation        = dispatch.Operations[i];
                    DispatchOperationRuntime operationRuntime = new DispatchOperationRuntime(operation, this);
                    demuxer.Add(operation.Action, operationRuntime);
                }

                demuxer.SetUnhandled(unhandled);
                this.demuxer = demuxer;
            }
            else
            {
                throw new PlatformNotSupportedException();
                //    CustomDemuxer demuxer = new CustomDemuxer(dispatch.OperationSelector);
                //    for (int i = 0; i < dispatch.Operations.Count; i++)
                //    {
                //        DispatchOperation operation = dispatch.Operations[i];
                //        DispatchOperationRuntime operationRuntime = new DispatchOperationRuntime(operation, this);
                //        demuxer.Add(operation.Name, operationRuntime);
                //    }

                //    demuxer.SetUnhandled(unhandled);
                //    this.demuxer = demuxer;
            }

            //processMessage1 = new MessageRpcProcessor(ProcessMessage1);
            //processMessage11 = new MessageRpcProcessor(ProcessMessage11);
            //processMessage2 = new MessageRpcProcessor(ProcessMessage2);
            //processMessage3 = new MessageRpcProcessor(ProcessMessage3);
            //processMessage31 = new MessageRpcProcessor(ProcessMessage31);
            //processMessage4 = new MessageRpcProcessor(ProcessMessage4);
            //processMessage41 = new MessageRpcProcessor(ProcessMessage41);
            //processMessage5 = new MessageRpcProcessor(ProcessMessage5);
            //processMessage6 = new MessageRpcProcessor(ProcessMessage6);
            //processMessage7 = new MessageRpcProcessor(ProcessMessage7);
            //processMessage8 = new MessageRpcProcessor(ProcessMessage8);
            //processMessage9 = new MessageRpcProcessor(ProcessMessage9);
            //processMessageCleanup = new MessageRpcProcessor(ProcessMessageCleanup);
            processMessageNonCleanupError = new MessageRpcErrorHandler(ProcessMessageNonCleanupError);
            processMessageCleanupError    = new MessageRpcErrorHandler(ProcessMessageCleanupError);
        }