Esempio n. 1
0
        internal void AfterReceiveReply(ref ProxyRpc rpc)
        {
            int offset = MessageInspectorCorrelationOffset;

            try
            {
                for (int i = 0; i < messageInspectors.Length; i++)
                {
                    messageInspectors[i].AfterReceiveReply(ref rpc.Reply, rpc.Correlation[offset + i]);
                    //if (TD.ClientMessageInspectorAfterReceiveInvokedIsEnabled())
                    //{
                    //    TD.ClientMessageInspectorAfterReceiveInvoked(rpc.EventTraceActivity, this.messageInspectors[i].GetType().FullName);
                    //}
                }
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                if (ErrorBehavior.ShouldRethrowClientSideExceptionAsIs(e))
                {
                    throw;
                }
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(e);
            }
        }
Esempio n. 2
0
        internal void Init()
        {
            errorBehavior = new ErrorBehavior(this);

            filterTable = new EndpointDispatcherTable(ThisLock);
            for (int i = 0; i < endpointDispatchers.Count; i++)
            {
                EndpointDispatcher endpoint = endpointDispatchers[i];

                // Force a build of the runtime to catch any unexpected errors before we are done opening.
                endpoint.DispatchRuntime.GetRuntime();
                // Lock down the DispatchRuntime.
                endpoint.DispatchRuntime.LockDownProperties();

                filterTable.AddEndpoint(endpoint);

                if ((addressTable != null) && (endpoint.OriginalAddress != null))
                {
                    addressTable.Add(endpoint.AddressFilter, endpoint.OriginalAddress, endpoint.FilterPriority);
                }

                //if (DiagnosticUtility.ShouldTraceInformation)
                //{
                //    this.TraceEndpointLifetime(endpoint, TraceCode.EndpointListenerOpen, SR.Format(SR.TraceCodeEndpointListenerOpen));
                //}
            }
        }
Esempio n. 3
0
        internal void BeforeSendRequest(ref ProxyRpc rpc)
        {
            int offset = MessageInspectorCorrelationOffset;

            try
            {
                for (int i = 0; i < messageInspectors.Length; i++)
                {
                    rpc.Correlation[offset + i] = messageInspectors[i].BeforeSendRequest(ref rpc.Request, (IClientChannel)rpc.Channel.Proxy);
                    //if (TD.ClientMessageInspectorBeforeSendInvokedIsEnabled())
                    //{
                    //    TD.ClientMessageInspectorBeforeSendInvoked(rpc.EventTraceActivity, this.messageInspectors[i].GetType().FullName);
                    //}
                }
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                if (ErrorBehavior.ShouldRethrowClientSideExceptionAsIs(e))
                {
                    throw;
                }
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(e);
            }

            //if (this.addTransactionFlowProperties)
            //{
            //    SendTransaction(ref rpc);
            //}
        }
Esempio n. 4
0
        internal bool HandleError(Exception error, ref ErrorHandlerFaultInfo faultInfo)
        {
            ErrorBehavior behavior;

            lock (ThisLock)
            {
                if (_errorBehavior != null)
                {
                    behavior = _errorBehavior;
                }
                else
                {
                    behavior = new ErrorBehavior(this);
                }
            }

            if (behavior != null)
            {
                return(behavior.HandleError(error, ref faultInfo));
            }
            else
            {
                return(false);
            }
        }
        void InitializeCallContextCore(MessageRpc rpc)
        {
            IClientChannel channel = rpc.Channel.Proxy as IClientChannel;
            int            offset  = Parent.CallContextCorrelationOffset;

            try
            {
                for (int i = 0; i < rpc.Operation.CallContextInitializers.Length; i++)
                {
                    ICallContextInitializer initializer = CallContextInitializers[i];
                    rpc.Correlation[offset + i] = initializer.BeforeInvoke(rpc.InstanceContext, channel, rpc.Request);
                }
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                if (ErrorBehavior.ShouldRethrowExceptionAsIs(e))
                {
                    throw;
                }
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(e);
            }
        }
Esempio n. 6
0
        internal void BeforeRequest(ref ProxyRpc rpc)
        {
            int offset = _parent.ParameterInspectorCorrelationOffset;

            try
            {
                for (int i = 0; i < _parameterInspectors.Length; i++)
                {
                    rpc.Correlation[offset + i] = _parameterInspectors[i].BeforeCall(_name, rpc.InputParameters);
                    //if (TD.ClientParameterInspectorBeforeCallInvokedIsEnabled())
                    //{
                    //    TD.ClientParameterInspectorBeforeCallInvoked(rpc.EventTraceActivity, this._parameterInspectors[i].GetType().FullName);
                    //}
                }
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                if (ErrorBehavior.ShouldRethrowClientSideExceptionAsIs(e))
                {
                    throw;
                }
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(e);
            }

            if (_serializeRequest)
            {
                //if (TD.ClientFormatterSerializeRequestStartIsEnabled())
                //{
                //    TD.ClientFormatterSerializeRequestStart(rpc.EventTraceActivity);
                //}

                rpc.Request = _formatter.SerializeRequest(rpc.MessageVersion, rpc.InputParameters);



                //if (TD.ClientFormatterSerializeRequestStopIsEnabled())
                //{
                //    TD.ClientFormatterSerializeRequestStop(rpc.EventTraceActivity);
                //}
            }
            else
            {
                if (rpc.InputParameters[0] == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.SFxProxyRuntimeMessageCannotBeNull, _name)));
                }

                rpc.Request = (Message)rpc.InputParameters[0];
                if (!IsValidAction(rpc.Request, Action))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.SFxInvalidRequestAction, Name, rpc.Request.Headers.Action ?? "{NULL}", Action)));
                }
            }
        }
        internal ImmutableDispatchRuntime(DispatchRuntime dispatch)
        {
            _authenticationBehavior = AuthenticationBehavior.TryCreate(dispatch);
            _authorizationBehavior  = AuthorizationBehavior.TryCreate(dispatch);
            _concurrency            = new ConcurrencyBehavior(dispatch);
            _error        = new ErrorBehavior(dispatch.ChannelDispatcher);
            _enableFaults = dispatch.EnableFaults;
            _inputSessionShutdownHandlers = EmptyArray <IInputSessionShutdown> .ToArray(dispatch.InputSessionShutdownHandlers);

            InstanceBehavior   = new InstanceBehavior(dispatch, this);
            _isOnServer        = dispatch.IsOnServer;
            _manualAddressing  = dispatch.ManualAddressing;
            _messageInspectors = EmptyArray <IDispatchMessageInspector> .ToArray(dispatch.MessageInspectors);

            _securityImpersonation = SecurityImpersonationBehavior.CreateIfNecessary(dispatch);
            RequireClaimsPrincipalOnOperationContext = dispatch.RequireClaimsPrincipalOnOperationContext;
            _impersonateOnSerializingReply           = dispatch.ImpersonateOnSerializingReply;
            _terminate             = TerminatingOperationBehavior.CreateIfNecessary(dispatch);
            _thread                = new ThreadBehavior(dispatch);
            ValidateMustUnderstand = dispatch.ValidateMustUnderstand;
            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);
                _demuxer = demuxer;
            }
            else
            {
                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);
                _demuxer = demuxer;
            }

            _processMessageNonCleanupError = new MessageRpcErrorHandler(ProcessMessageNonCleanupError);
            _processMessageCleanupError    = new MessageRpcErrorHandler(ProcessMessageCleanupError);
        }
Esempio n. 8
0
        private async Task ReplyFailureAsync(RequestContext request, RequestInfo requestInfo, Message fault, string action, string reason, FaultCode code)
        {
            FaultException exception = new FaultException(reason, code);

            ErrorBehavior.ThrowAndCatch(exception);
            ErrorHandlerFaultInfo faultInfo = new ErrorHandlerFaultInfo(action);

            faultInfo.Fault = fault;
            faultInfo       = await ProvideFaultAndReplyFailureAsync(request, requestInfo, exception, faultInfo);

            HandleError(exception, ref faultInfo);
        }
Esempio n. 9
0
        internal ProxyOperationRuntime GetOperation(MethodBase methodBase, object[] args, out bool canCacheResult)
        {
            if (operationSelector == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException
                                                                              (SR.Format(SR.SFxNeedProxyBehaviorOperationSelector2, methodBase.Name,
                                                                                         methodBase.DeclaringType.Name)));
            }

            try
            {
                if (operationSelector.AreParametersRequiredForSelection)
                {
                    canCacheResult = false;
                }
                else
                {
                    args           = null;
                    canCacheResult = true;
                }
                string operationName = operationSelector.SelectOperation(methodBase, args);
                ProxyOperationRuntime operation;
                if ((operationName != null) && operations.TryGetValue(operationName, out operation))
                {
                    return(operation);
                }
                else
                {
                    // did not find the right operation, will not know how
                    // to invoke the method.
                    return(null);
                }
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                if (ErrorBehavior.ShouldRethrowClientSideExceptionAsIs(e))
                {
                    throw;
                }
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(e);
            }
        }
Esempio n. 10
0
        // TODO: Move this functionality somewhere else as this class is now OM only
        internal void ProvideFault(Exception e, FaultConverter faultConverter, ref ErrorHandlerFaultInfo faultInfo)
        {
            ErrorBehavior behavior;

            lock (ThisLock)
            {
                if (_errorBehavior != null)
                {
                    behavior = _errorBehavior;
                }
                else
                {
                    behavior = new ErrorBehavior(this);
                }
            }

            behavior.ProvideFault(e, faultConverter, ref faultInfo);
        }
Esempio n. 11
0
        // this should not be inlined, since we want to JIT the reference to System.Transactions
        // only if transactions are being flowed.
        //[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
        //static void SendTransaction(ref ProxyRpc rpc)
        //{
        //    System.ServiceModel.Channels.TransactionFlowProperty.Set(Transaction.Current, rpc.Request);
        //}

        internal void InitializeChannel(IClientChannel channel)
        {
            try
            {
                for (int i = 0; i < channelInitializers.Length; ++i)
                {
                    channelInitializers[i].Initialize(channel);
                }
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                if (ErrorBehavior.ShouldRethrowClientSideExceptionAsIs(e))
                {
                    throw;
                }
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(e);
            }
        }
Esempio n. 12
0
        internal void AfterReply(ref MessageRpc rpc, ErrorBehavior error)
        {
            InstanceContext context = rpc.InstanceContext;

            if (context != null)
            {
                try
                {
                    if (rpc.Operation.ReleaseInstanceAfterCall)
                    {
                        if (context.State == CommunicationState.Opened)
                        {
                            context.ReleaseServiceInstance();
                        }
                    }
                }
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }
                    error.HandleError(e);
                }

                try
                {
                    context.UnbindRpc(rpc);
                }
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }
                    error.HandleError(e);
                }
            }
        }
Esempio n. 13
0
        void SerializeOutputs(ref MessageRpc rpc)
        {
            if (!IsOneWay && parent.EnableFaults)
            {
                Message reply;
                if (serializeReply)
                {
                    try
                    {
                        //if (TD.DispatchFormatterSerializeReplyStartIsEnabled())
                        //{
                        //    TD.DispatchFormatterSerializeReplyStart(rpc.EventTraceActivity);
                        //}

                        reply = Formatter.SerializeReply(rpc.RequestVersion, rpc.OutputParameters, rpc.ReturnParameter);

                        //if (TD.DispatchFormatterSerializeReplyStopIsEnabled())
                        //{
                        //    TD.DispatchFormatterSerializeReplyStop(rpc.EventTraceActivity);
                        //}
                    }
                    catch (Exception e)
                    {
                        if (Fx.IsFatal(e))
                        {
                            throw;
                        }
                        if (ErrorBehavior.ShouldRethrowExceptionAsIs(e))
                        {
                            throw;
                        }
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(e);
                    }

                    if (reply == null)
                    {
                        string message = SR.Format(SR.SFxNullReplyFromFormatter2, Formatter.GetType().ToString(), (name ?? ""));
                        ErrorBehavior.ThrowAndCatch(new InvalidOperationException(message));
                    }
                }
                else
                {
                    if ((rpc.ReturnParameter == null) && (rpc.OperationContext.RequestContext != null))
                    {
                        string message = SR.Format(SR.SFxDispatchRuntimeMessageCannotBeNull, name);
                        ErrorBehavior.ThrowAndCatch(new InvalidOperationException(message));
                    }

                    reply = (Message)rpc.ReturnParameter;

                    if ((reply != null) && (!ProxyOperationRuntime.IsValidAction(reply, ReplyAction)))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.SFxInvalidReplyAction, Name, reply.Headers.Action ?? "{NULL}", ReplyAction)));
                    }
                }

                //if (DiagnosticUtility.ShouldUseActivity && rpc.Activity != null && reply != null)
                //{
                //    TraceUtility.SetActivity(reply, rpc.Activity);
                //    if (TraceUtility.ShouldPropagateActivity)
                //    {
                //        TraceUtility.AddActivityHeader(reply);
                //    }
                //}
                //else if (TraceUtility.ShouldPropagateActivity && reply != null && rpc.ResponseActivityId != Guid.Empty)
                //{
                //    ActivityIdHeader header = new ActivityIdHeader(rpc.ResponseActivityId);
                //    header.AddTo(reply);
                //}

                //rely on the property set during the message receive to correlate the trace
                //if (TraceUtility.MessageFlowTracingOnly)
                //{
                //    //Guard against MEX scenarios where the message is closed by now
                //    if (null != rpc.OperationContext.IncomingMessage && MessageState.Closed != rpc.OperationContext.IncomingMessage.State)
                //    {
                //        FxTrace.Trace.SetAndTraceTransfer(TraceUtility.GetReceivedActivityId(rpc.OperationContext), true);
                //    }
                //    else
                //    {
                //        if (rpc.ResponseActivityId != Guid.Empty)
                //        {
                //            FxTrace.Trace.SetAndTraceTransfer(rpc.ResponseActivityId, true);
                //        }
                //    }
                //}

                // Add the ImpersonateOnSerializingReplyMessageProperty on the reply message iff
                // a. reply message is not null.
                // b. Impersonation is enabled on serializing Reply

                //if (reply != null && this.parent.IsImpersonationEnabledOnSerializingReply)
                //{
                //    bool shouldImpersonate = this.parent.SecurityImpersonation != null && this.parent.SecurityImpersonation.IsImpersonationEnabledOnCurrentOperation(ref rpc);
                //    if (shouldImpersonate)
                //    {
                //        reply.Properties.Add(ImpersonateOnSerializingReplyMessageProperty.Name, new ImpersonateOnSerializingReplyMessageProperty(ref rpc));
                //        reply = new ImpersonatingMessage(reply);
                //    }
                //}

                //if (MessageLogger.LoggingEnabled && null != reply)
                //{
                //    MessageLogger.LogMessage(ref reply, MessageLoggingSource.ServiceLevelSendReply | MessageLoggingSource.LastChance);
                //}
                rpc.Reply = reply;
            }
        }
Esempio n. 14
0
        //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);
        }
Esempio n. 15
0
        internal void AfterReply(ref ProxyRpc rpc)
        {
            if (!_isOneWay)
            {
                Message reply = rpc.Reply;

                if (_deserializeReply)
                {
                    //if (TD.ClientFormatterDeserializeReplyStartIsEnabled())
                    //{
                    //    TD.ClientFormatterDeserializeReplyStart(rpc.EventTraceActivity);
                    //}

                    rpc.ReturnValue = _formatter.DeserializeReply(reply, rpc.OutputParameters);

                    //if (TD.ClientFormatterDeserializeReplyStopIsEnabled())
                    //{
                    //    TD.ClientFormatterDeserializeReplyStop(rpc.EventTraceActivity);
                    //}
                }
                else
                {
                    rpc.ReturnValue = reply;
                }

                int offset = _parent.ParameterInspectorCorrelationOffset;
                try
                {
                    for (int i = _parameterInspectors.Length - 1; i >= 0; i--)
                    {
                        _parameterInspectors[i].AfterCall(_name,
                                                          rpc.OutputParameters,
                                                          rpc.ReturnValue,
                                                          rpc.Correlation[offset + i]);
                        //if (TD.ClientParameterInspectorAfterCallInvokedIsEnabled())
                        //{
                        //    TD.ClientParameterInspectorAfterCallInvoked(rpc.EventTraceActivity, this._parameterInspectors[i].GetType().FullName);
                        //}
                    }
                }
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }
                    if (ErrorBehavior.ShouldRethrowClientSideExceptionAsIs(e))
                    {
                        throw;
                    }
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(e);
                }

                if (_parent.ValidateMustUnderstand)
                {
                    Collection <MessageHeaderInfo> headersNotUnderstood = reply.Headers.GetHeadersNotUnderstood();
                    if (headersNotUnderstood != null && headersNotUnderstood.Count > 0)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(SR.Format(SR.SFxHeaderNotUnderstood, headersNotUnderstood[0].Name, headersNotUnderstood[0].Namespace)));
                    }
                }
            }
        }
Esempio n. 16
0
            public object Invoke(object instance, object[] inputs, out object[] outputs)
            {
                outputs = EmptyArray <object> .Allocate(0);

                Message message = inputs[0] as Message;

                if (message == null)
                {
                    return(null);
                }

                string action = message.Headers.Action;

                //if (DiagnosticUtility.ShouldTraceInformation)
                //{
                //    TraceUtility.TraceEvent(TraceEventType.Information, TraceCode.UnhandledAction,
                //        SR.TraceCodeUnhandledAction,
                //        new StringTraceRecord("Action", action),
                //        this, null, message);
                //}

                FaultCode code = FaultCode.CreateSenderFaultCode(AddressingStrings.ActionNotSupported,
                                                                 message.Version.Addressing.Namespace);
                string      reasonText = SR.Format(SR.SFxNoEndpointMatchingContract, action);
                FaultReason reason     = new FaultReason(reasonText);

                FaultException exception = new FaultException(reason, code);

                ErrorBehavior.ThrowAndCatch(exception);

                ServiceChannel serviceChannel = OperationContext.Current.InternalServiceChannel;

                OperationContext.Current.OperationCompleted +=
                    delegate(object sender, EventArgs e)
                {
                    ChannelDispatcher channelDispatcher = dispatchRuntime.ChannelDispatcher;
                    if (!channelDispatcher.HandleError(exception) && serviceChannel.HasSession)
                    {
                        try
                        {
                            var helper = new TimeoutHelper(ChannelHandler.CloseAfterFaultTimeout);
                            serviceChannel.CloseAsync(helper.GetCancellationToken()).GetAwaiter().GetResult();
                        }
                        catch (Exception ex)
                        {
                            if (Fx.IsFatal(ex))
                            {
                                throw;
                            }
                            channelDispatcher.HandleError(ex);
                        }
                    }
                };

                if (dispatchRuntime.shared.EnableFaults)
                {
                    MessageFault fault = MessageFault.CreateFault(code, reason, action);
                    return(Message.CreateMessage(message.Version, fault, message.Version.Addressing.DefaultFaultAction));
                }
                else
                {
                    OperationContext.Current.RequestContext.CloseAsync().GetAwaiter().GetResult();
                    OperationContext.Current.RequestContext = null;
                    return(null);
                }
            }
        //internal bool TransactionAutoComplete
        //{
        //    get { return this.transactionAutoComplete; }
        //}

        //internal bool TransactionRequired
        //{
        //    get { return this.transactionRequired; }
        //}

        //internal bool IsInsideTransactedReceiveScope
        //{
        //    get { return this.isInsideTransactedReceiveScope; }
        //}

        void DeserializeInputs(MessageRpc rpc)
        {
            //bool success = false;
            try
            {
                try
                {
                    rpc.InputParameters = Invoker.AllocateInputs();
                }
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }
                    if (ErrorBehavior.ShouldRethrowExceptionAsIs(e))
                    {
                        throw;
                    }
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(e);
                }
                try
                {
                    // If the field is true, then this operation is to be invoked at the time the service
                    // channel is opened. The incoming message is created at ChannelHandler level with no
                    // content, so we don't need to deserialize the message.
                    if (!isSessionOpenNotificationEnabled)
                    {
                        if (deserializeRequest)
                        {
                            //if (TD.DispatchFormatterDeserializeRequestStartIsEnabled())
                            //{
                            //    TD.DispatchFormatterDeserializeRequestStart(rpc.EventTraceActivity);
                            //}

                            Formatter.DeserializeRequest(rpc.Request, rpc.InputParameters);

                            //if (TD.DispatchFormatterDeserializeRequestStopIsEnabled())
                            //{
                            //    TD.DispatchFormatterDeserializeRequestStop(rpc.EventTraceActivity);
                            //}
                        }
                        else
                        {
                            rpc.InputParameters[0] = rpc.Request;
                        }
                    }

                    //success = true;
                }
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }
                    if (ErrorBehavior.ShouldRethrowExceptionAsIs(e))
                    {
                        throw;
                    }
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(e);
                }
            }
            finally
            {
                rpc.DidDeserializeRequestBody = (rpc.Request.State != MessageState.Created);

                //if (!success && MessageLogger.LoggingEnabled)
                //{
                //    MessageLogger.LogMessage(rpc.Request, MessageLoggingSource.Malformed);
                //}
            }
        }