Exemplo n.º 1
0
        private void InitializeCallContextCore(ref MessageRpc rpc)
        {
            IClientChannel proxy = rpc.Channel.Proxy as IClientChannel;
            int            callContextCorrelationOffset = this.Parent.CallContextCorrelationOffset;

            try
            {
                for (int i = 0; i < rpc.Operation.CallContextInitializers.Length; i++)
                {
                    rpc.Correlation[callContextCorrelationOffset + i] = this.CallContextInitializers[i].BeforeInvoke(rpc.InstanceContext, proxy, rpc.Request);
                }
            }
            catch (Exception exception)
            {
                if (Fx.IsFatal(exception))
                {
                    throw;
                }
                if (ErrorBehavior.ShouldRethrowExceptionAsIs(exception))
                {
                    throw;
                }
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(exception);
            }
        }
Exemplo n.º 2
0
        internal void AfterReceiveRequestCore(ref MessageRpc rpc)
        {
            int offset = MessageInspectorCorrelationOffset;

            try
            {
                for (int i = 0; i < _messageInspectors.Length; i++)
                {
                    rpc.Correlation[offset + i] = _messageInspectors[i].AfterReceiveRequest(ref rpc.Request, (IClientChannel)rpc.Channel.Proxy, rpc.InstanceContext);
                    if (WcfEventSource.Instance.MessageInspectorAfterReceiveInvokedIsEnabled())
                    {
                        WcfEventSource.Instance.MessageInspectorAfterReceiveInvoked(rpc.EventTraceActivity, _messageInspectors[i].GetType().FullName);
                    }
                }
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                if (ErrorBehavior.ShouldRethrowExceptionAsIs(e))
                {
                    throw;
                }
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(e);
            }
        }
Exemplo n.º 3
0
        protected override void OnOpened()
        {
            this.ThrowIfNotAttachedToHost();
            base.OnOpened();
            this.errorBehavior = new ErrorBehavior(this);
            this.filterTable   = new System.ServiceModel.Dispatcher.EndpointDispatcherTable(base.ThisLock);
            for (int i = 0; i < this.endpointDispatchers.Count; i++)
            {
                EndpointDispatcher endpoint = this.endpointDispatchers[i];
                endpoint.DispatchRuntime.GetRuntime();
                endpoint.DispatchRuntime.LockDownProperties();
                this.filterTable.AddEndpoint(endpoint);
                if ((this.addressTable != null) && (endpoint.OriginalAddress != null))
                {
                    this.addressTable.Add(endpoint.AddressFilter, endpoint.OriginalAddress, endpoint.FilterPriority);
                }
                if (DiagnosticUtility.ShouldTraceInformation)
                {
                    this.TraceEndpointLifetime(endpoint, 0x40008, System.ServiceModel.SR.GetString("TraceCodeEndpointListenerOpen"));
                }
            }
            System.ServiceModel.Dispatcher.ServiceThrottle serviceThrottle = this.serviceThrottle;
            if (serviceThrottle == null)
            {
                serviceThrottle = this.host.ServiceThrottle;
            }
            IListenerBinder listenerBinder = ListenerBinder.GetBinder(this.listener, this.messageVersion);

            this.listenerHandler = new ListenerHandler(listenerBinder, this, this.host, serviceThrottle, this.timeouts);
            this.listenerHandler.Open();
        }
        internal void AfterReceiveReply(ref ProxyRpc rpc)
        {
            int messageInspectorCorrelationOffset = this.MessageInspectorCorrelationOffset;

            try
            {
                for (int i = 0; i < this.messageInspectors.Length; i++)
                {
                    this.messageInspectors[i].AfterReceiveReply(ref rpc.Reply, rpc.Correlation[messageInspectorCorrelationOffset + i]);
                    if (TD.ClientMessageInspectorAfterReceiveInvokedIsEnabled())
                    {
                        TD.ClientMessageInspectorAfterReceiveInvoked(this.messageInspectors[i].GetType().FullName);
                    }
                }
            }
            catch (Exception exception)
            {
                if (Fx.IsFatal(exception))
                {
                    throw;
                }
                if (ErrorBehavior.ShouldRethrowClientSideExceptionAsIs(exception))
                {
                    throw;
                }
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(exception);
            }
        }
        internal void BeforeSendRequest(ref ProxyRpc rpc)
        {
            int messageInspectorCorrelationOffset = this.MessageInspectorCorrelationOffset;

            try
            {
                for (int i = 0; i < this.messageInspectors.Length; i++)
                {
                    rpc.Correlation[messageInspectorCorrelationOffset + i] = this.messageInspectors[i].BeforeSendRequest(ref rpc.Request, (IClientChannel)rpc.Channel.Proxy);
                    if (TD.ClientMessageInspectorBeforeSendInvokedIsEnabled())
                    {
                        TD.ClientMessageInspectorBeforeSendInvoked(this.messageInspectors[i].GetType().FullName);
                    }
                }
            }
            catch (Exception exception)
            {
                if (Fx.IsFatal(exception))
                {
                    throw;
                }
                if (ErrorBehavior.ShouldRethrowClientSideExceptionAsIs(exception))
                {
                    throw;
                }
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(exception);
            }
            if (this.addTransactionFlowProperties)
            {
                SendTransaction(ref rpc);
            }
        }
Exemplo n.º 6
0
        internal void AfterReceiveReply(ref ProxyRpc rpc)
        {
            int offset = this.MessageInspectorCorrelationOffset;

            try
            {
                for (int i = 0; i < _messageInspectors.Length; i++)
                {
                    _messageInspectors[i].AfterReceiveReply(ref rpc.Reply, rpc.Correlation[offset + i]);
                    if (WcfEventSource.Instance.ClientMessageInspectorAfterReceiveInvokedIsEnabled())
                    {
                        WcfEventSource.Instance.ClientMessageInspectorAfterReceiveInvoked(rpc.EventTraceActivity, _messageInspectors[i].GetType().FullName);
                    }
                }
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                if (ErrorBehavior.ShouldRethrowClientSideExceptionAsIs(e))
                {
                    throw;
                }
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(e);
            }
        }
Exemplo n.º 7
0
        internal bool HandleError(Exception error, ref ErrorHandlerFaultInfo faultInfo)
        {
            ErrorBehavior behavior;

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

            if (behavior != null)
            {
                return(behavior.HandleError(error, ref faultInfo));
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 8
0
        protected override void OnOpened()
        {
            base.OnOpened();

            if (WcfEventSource.Instance.ListenerOpenStopIsEnabled())
            {
                WcfEventSource.Instance.ListenerOpenStop(_eventTraceActivity);
                _eventTraceActivity = null; // clear this since we don't need this anymore.
            }

            _errorBehavior = new ErrorBehavior(this);

            _filterTable = new EndpointDispatcherTable(this.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.
                // Lock down the DispatchRuntime.
                endpoint.DispatchRuntime.LockDownProperties();

                _filterTable.AddEndpoint(endpoint);
            }

            IListenerBinder binder = ListenerBinder.GetBinder(_listener, _messageVersion);

            _listenerHandler = new ListenerHandler(binder, this, _timeouts);
            _listenerHandler.Open();  // This never throws, which is why it's ok for it to happen in OnOpened
        }
Exemplo n.º 9
0
        internal void BeforeSendRequest(ref ProxyRpc rpc)
        {
            int offset = this.MessageInspectorCorrelationOffset;

            try
            {
                for (int i = 0; i < _messageInspectors.Length; i++)
                {
                    ServiceChannel clientChannel = ServiceChannelFactory.GetServiceChannel(rpc.Channel.Proxy);
                    rpc.Correlation[offset + i] = _messageInspectors[i].BeforeSendRequest(ref rpc.Request, clientChannel);
                    if (WcfEventSource.Instance.ClientMessageInspectorBeforeSendInvokedIsEnabled())
                    {
                        WcfEventSource.Instance.ClientMessageInspectorBeforeSendInvoked(rpc.EventTraceActivity, _messageInspectors[i].GetType().FullName);
                    }
                }
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                if (ErrorBehavior.ShouldRethrowClientSideExceptionAsIs(e))
                {
                    throw;
                }
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(e);
            }
        }
Exemplo n.º 10
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 (WcfEventSource.Instance.ClientParameterInspectorBeforeCallInvokedIsEnabled())
                    {
                        WcfEventSource.Instance.ClientParameterInspectorBeforeCallInvoked(rpc.EventTraceActivity, _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 (WcfEventSource.Instance.ClientFormatterSerializeRequestStartIsEnabled())
                {
                    WcfEventSource.Instance.ClientFormatterSerializeRequestStart(rpc.EventTraceActivity);
                }

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



                if (WcfEventSource.Instance.ClientFormatterSerializeRequestStopIsEnabled())
                {
                    WcfEventSource.Instance.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, this.Name, rpc.Request.Headers.Action ?? "{NULL}", this.Action)));
                }
            }
        }
Exemplo n.º 11
0
            public Task <object> InvokeAsync(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;

                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
                        {
                            serviceChannel.Close(ChannelHandler.CloseAfterFaultTimeout);
                        }
                        catch (Exception ex)
                        {
                            if (Fx.IsFatal(ex))
                            {
                                throw;
                            }
                            channelDispatcher.HandleError(ex);
                        }
                    }
                };

                if (_dispatchRuntime._shared.EnableFaults)
                {
                    MessageFault fault = MessageFault.CreateFault(code, reason, action);
                    return(Task.FromResult((object)Message.CreateMessage(message.Version, fault, message.Version.Addressing.DefaultFaultAction)));
                }
                else
                {
                    OperationContext.Current.RequestContext.Close();
                    OperationContext.Current.RequestContext = null;
                    return(Task.FromResult((object)null));
                }
            }
Exemplo n.º 12
0
        private void DeserializeInputs(ref MessageRpc rpc)
        {
            bool flag = false;

            try
            {
                try
                {
                    rpc.InputParameters = this.Invoker.AllocateInputs();
                }
                catch (Exception exception)
                {
                    if (Fx.IsFatal(exception))
                    {
                        throw;
                    }
                    if (ErrorBehavior.ShouldRethrowExceptionAsIs(exception))
                    {
                        throw;
                    }
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(exception);
                }
                try
                {
                    if (this.deserializeRequest)
                    {
                        this.Formatter.DeserializeRequest(rpc.Request, rpc.InputParameters);
                    }
                    else
                    {
                        rpc.InputParameters[0] = rpc.Request;
                    }
                    flag = true;
                }
                catch (Exception exception2)
                {
                    if (Fx.IsFatal(exception2))
                    {
                        throw;
                    }
                    if (ErrorBehavior.ShouldRethrowExceptionAsIs(exception2))
                    {
                        throw;
                    }
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(exception2);
                }
            }
            finally
            {
                rpc.DidDeserializeRequestBody = rpc.Request.State != MessageState.Created;
                if (!flag && MessageLogger.LoggingEnabled)
                {
                    MessageLogger.LogMessage(ref rpc.Request, MessageLoggingSource.Malformed);
                }
            }
        }
Exemplo n.º 13
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();
                        }
                    }
                    else if (releaseServiceInstanceOnTransactionComplete &&
                             this.isSynchronized &&
                             rpc.transaction != null &&
                             (rpc.transaction.IsCompleted || (rpc.Error != null)))
                    {
                        if (context.State == CommunicationState.Opened)
                        {
                            context.ReleaseServiceInstance();
                        }
                        if (DiagnosticUtility.ShouldTraceInformation)
                        {
                            TraceUtility.TraceEvent(TraceEventType.Information,
                                                    TraceCode.TxReleaseServiceInstanceOnCompletion,
                                                    SR.GetString(SR.TraceCodeTxReleaseServiceInstanceOnCompletion, "*"));
                        }
                    }
                }
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }
                    error.HandleError(e);
                }

                try
                {
                    context.UnbindRpc(ref rpc);
                }
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }
                    error.HandleError(e);
                }
            }
        }
Exemplo n.º 14
0
        private void ReplyFailure(RequestContext request, 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;
            bool replied, replySentAsync;

            ProvideFaultAndReplyFailure(request, exception, ref faultInfo, out replied, out replySentAsync);
            this.HandleError(exception, ref faultInfo);
        }
Exemplo n.º 15
0
        internal void BeforeSendRequest(ref ProxyRpc rpc)
        {
            int offset = this.MessageInspectorCorrelationOffset;

            try
            {
                bool      outputTiming = DS.MessageInspectorIsEnabled();
                Stopwatch sw           = null;
                if (outputTiming)
                {
                    sw = new Stopwatch();
                }

                for (int i = 0; i < this.messageInspectors.Length; i++)
                {
                    if (outputTiming)
                    {
                        sw.Restart();
                    }

                    rpc.Correlation[offset + i] = this.messageInspectors[i].BeforeSendRequest(ref rpc.Request, (IClientChannel)rpc.Channel.Proxy);
                    if (outputTiming)
                    {
                        DS.ClientMessageInspectorBeforeSend(this.messageInspectors[i].GetType(), sw.Elapsed);
                    }

                    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);
            }
        }
        internal void AfterReply(ref MessageRpc rpc, ErrorBehavior error)
        {
            InstanceContext instanceContext = rpc.InstanceContext;

            if (instanceContext != null)
            {
                try
                {
                    if (rpc.Operation.ReleaseInstanceAfterCall)
                    {
                        if (instanceContext.State == CommunicationState.Opened)
                        {
                            instanceContext.ReleaseServiceInstance();
                        }
                    }
                    else if (((this.releaseServiceInstanceOnTransactionComplete && this.isSynchronized) && (rpc.transaction != null)) && (rpc.transaction.IsCompleted || (rpc.Error != null)))
                    {
                        if (instanceContext.State == CommunicationState.Opened)
                        {
                            instanceContext.ReleaseServiceInstance();
                        }
                        if (DiagnosticUtility.ShouldTraceInformation)
                        {
                            TraceUtility.TraceEvent(TraceEventType.Information, 0xe000c, System.ServiceModel.SR.GetString("TraceCodeTxReleaseServiceInstanceOnCompletion", new object[] { "*" }));
                        }
                    }
                }
                catch (Exception exception)
                {
                    if (Fx.IsFatal(exception))
                    {
                        throw;
                    }
                    error.HandleError(exception);
                }
                try
                {
                    instanceContext.UnbindRpc(ref rpc);
                }
                catch (Exception exception2)
                {
                    if (Fx.IsFatal(exception2))
                    {
                        throw;
                    }
                    error.HandleError(exception2);
                }
            }
        }
 internal void AfterReply(ref MessageRpc rpc, ErrorBehavior error)
 {
     InstanceContext instanceContext = rpc.InstanceContext;
     if (instanceContext != null)
     {
         try
         {
             if (rpc.Operation.ReleaseInstanceAfterCall)
             {
                 if (instanceContext.State == CommunicationState.Opened)
                 {
                     instanceContext.ReleaseServiceInstance();
                 }
             }
             else if (((this.releaseServiceInstanceOnTransactionComplete && this.isSynchronized) && (rpc.transaction != null)) && (rpc.transaction.IsCompleted || (rpc.Error != null)))
             {
                 if (instanceContext.State == CommunicationState.Opened)
                 {
                     instanceContext.ReleaseServiceInstance();
                 }
                 if (DiagnosticUtility.ShouldTraceInformation)
                 {
                     TraceUtility.TraceEvent(TraceEventType.Information, 0xe000c, System.ServiceModel.SR.GetString("TraceCodeTxReleaseServiceInstanceOnCompletion", new object[] { "*" }));
                 }
             }
         }
         catch (Exception exception)
         {
             if (Fx.IsFatal(exception))
             {
                 throw;
             }
             error.HandleError(exception);
         }
         try
         {
             instanceContext.UnbindRpc(ref rpc);
         }
         catch (Exception exception2)
         {
             if (Fx.IsFatal(exception2))
             {
                 throw;
             }
             error.HandleError(exception2);
         }
     }
 }
Exemplo n.º 18
0
        protected override void OnOpened()
        {
            ThrowIfNotAttachedToHost();
            base.OnOpened();

            if (TD.ListenerOpenStopIsEnabled())
            {
                TD.ListenerOpenStop(this.eventTraceActivity);
                this.eventTraceActivity = null; // clear this since we don't need this anymore.
            }

            this.errorBehavior = new ErrorBehavior(this);

            this.filterTable = new EndpointDispatcherTable(this.ThisLock);
            for (int i = 0; i < this.endpointDispatchers.Count; i++)
            {
                EndpointDispatcher endpoint = this.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();

                this.filterTable.AddEndpoint(endpoint);

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

                if (DiagnosticUtility.ShouldTraceInformation)
                {
                    this.TraceEndpointLifetime(endpoint, TraceCode.EndpointListenerOpen, SR.GetString(SR.TraceCodeEndpointListenerOpen));
                }
            }

            ServiceThrottle throttle = this.serviceThrottle;

            if (throttle == null)
            {
                throttle = this.host.ServiceThrottle;
            }

            IListenerBinder binder = ListenerBinder.GetBinder(this.listener, this.messageVersion);

            this.listenerHandler = new ListenerHandler(binder, this, this.host, throttle, this.timeouts);
            this.listenerHandler.Open();  // This never throws, which is why it's ok for it to happen in OnOpened
        }
Exemplo n.º 19
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);
            }
        }
Exemplo n.º 20
0
        internal bool HandleError(Exception error, ref ErrorHandlerFaultInfo faultInfo)
        {
            ErrorBehavior errorBehavior;

            lock (base.ThisLock)
            {
                if (this.errorBehavior != null)
                {
                    errorBehavior = this.errorBehavior;
                }
                else
                {
                    errorBehavior = new ErrorBehavior(this);
                }
            }
            return((errorBehavior != null) && errorBehavior.HandleError(error, ref faultInfo));
        }
Exemplo n.º 21
0
        internal void ProvideFault(Exception e, FaultConverter faultConverter, ref ErrorHandlerFaultInfo faultInfo)
        {
            ErrorBehavior errorBehavior;

            lock (base.ThisLock)
            {
                if (this.errorBehavior != null)
                {
                    errorBehavior = this.errorBehavior;
                }
                else
                {
                    errorBehavior = new ErrorBehavior(this);
                }
            }
            errorBehavior.ProvideFault(e, faultConverter, ref faultInfo);
        }
Exemplo n.º 22
0
        internal void AfterReceiveReply(ref ProxyRpc rpc)
        {
            int       offset       = this.MessageInspectorCorrelationOffset;
            bool      outputTiming = DS.MessageInspectorIsEnabled();
            Stopwatch sw           = null;

            if (outputTiming)
            {
                sw = new Stopwatch();
            }

            try
            {
                for (int i = 0; i < this.messageInspectors.Length; i++)
                {
                    if (outputTiming)
                    {
                        sw.Restart();
                    }

                    this.messageInspectors[i].AfterReceiveReply(ref rpc.Reply, rpc.Correlation[offset + i]);
                    if (outputTiming)
                    {
                        DS.ClientMessageInspectorAfterReceive(this.messageInspectors[i].GetType(), sw.Elapsed);
                    }

                    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);
            }
        }
Exemplo n.º 23
0
        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);
        }
Exemplo n.º 24
0
        internal void BeforeSendReplyCore(ref MessageRpc rpc, ref Exception exception, ref bool thereIsAnUnhandledException)
        {
            int offset = MessageInspectorCorrelationOffset;

            for (int i = 0; i < _messageInspectors.Length; i++)
            {
                try
                {
                    Message originalReply = rpc.Reply;
                    Message reply         = originalReply;

                    _messageInspectors[i].BeforeSendReply(ref reply, rpc.Correlation[offset + i]);
                    if (WcfEventSource.Instance.MessageInspectorBeforeSendInvokedIsEnabled())
                    {
                        WcfEventSource.Instance.MessageInspectorBeforeSendInvoked(rpc.EventTraceActivity, _messageInspectors[i].GetType().FullName);
                    }

                    if ((reply == null) && (originalReply != null))
                    {
                        string message = SR.Format(SR.SFxNullReplyFromExtension2, _messageInspectors[i].GetType().ToString(), (rpc.Operation.Name ?? ""));
                        ErrorBehavior.ThrowAndCatch(new InvalidOperationException(message));
                    }
                    rpc.Reply = reply;
                }
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }
                    if (!ErrorBehavior.ShouldRethrowExceptionAsIs(e))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(e);
                    }

                    if (exception == null)
                    {
                        exception = e;
                    }
                    thereIsAnUnhandledException = (!_error.HandleError(e)) || thereIsAnUnhandledException;
                }
            }
        }
Exemplo n.º 25
0
        internal ImmutableDispatchRuntime(DispatchRuntime dispatch)
        {
            _concurrency       = new ConcurrencyBehavior(dispatch);
            _error             = new ErrorBehavior(dispatch.ChannelDispatcher);
            EnableFaults       = dispatch.EnableFaults;
            _instance          = new InstanceBehavior(dispatch, this);
            ManualAddressing   = dispatch.ManualAddressing;
            _messageInspectors = EmptyArray <IDispatchMessageInspector> .ToArray(dispatch.MessageInspectors);

            _terminate          = TerminatingOperationBehavior.CreateIfNecessary(dispatch);
            _thread             = new ThreadBehavior(dispatch);
            _sendAsynchronously = dispatch.ChannelDispatcher.SendAsynchronously;
            CorrelationCount    = dispatch.MaxParameterInspectors;

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

            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;

            _processMessage1            = ProcessMessage1;
            _processMessage11           = ProcessMessage11;
            _processMessage2            = ProcessMessage2;
            _processMessage3            = ProcessMessage3;
            _processMessage31           = ProcessMessage31;
            _processMessage4            = ProcessMessage4;
            _processMessage41           = ProcessMessage41;
            _processMessage5            = ProcessMessage5;
            _processMessage6            = ProcessMessage6;
            _processMessage7            = ProcessMessage7;
            _processMessage8            = ProcessMessage8;
            _processMessage9            = ProcessMessage9;
            _processMessageCleanup      = ProcessMessageCleanup;
            _processMessageCleanupError = ProcessMessageCleanupError;
        }
Exemplo n.º 26
0
        internal void AfterReply(ref MessageRpc rpc, ErrorBehavior error)
        {
            InstanceContext context = rpc.InstanceContext;

            if (context != null)
            {
                try
                {
                    context.UnbindRpc(ref rpc);
                }
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }
                    error.HandleError(e);
                }
            }
        }
Exemplo n.º 27
0
        internal void AfterReply(ref MessageRpc rpc, ErrorBehavior error)
        {
            InstanceContext context = rpc.InstanceContext;

            if (context != null)
            {
                try
                {
                    context.UnbindRpc(ref rpc);
                }
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }
                    error.HandleError(e);
                }
            }
        }
        internal ProxyOperationRuntime GetOperation(MethodBase methodBase, object[] args, out bool canCacheResult)
        {
            ProxyOperationRuntime runtime2;

            if (this.operationSelector == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(System.ServiceModel.SR.GetString("SFxNeedProxyBehaviorOperationSelector2", new object[] { methodBase.Name, methodBase.DeclaringType.Name })));
            }
            try
            {
                ProxyOperationRuntime runtime;
                if (this.operationSelector.AreParametersRequiredForSelection)
                {
                    canCacheResult = false;
                }
                else
                {
                    args           = null;
                    canCacheResult = true;
                }
                string key = this.operationSelector.SelectOperation(methodBase, args);
                if ((key != null) && this.operations.TryGetValue(key, out runtime))
                {
                    return(runtime);
                }
                runtime2 = null;
            }
            catch (Exception exception)
            {
                if (Fx.IsFatal(exception))
                {
                    throw;
                }
                if (ErrorBehavior.ShouldRethrowClientSideExceptionAsIs(exception))
                {
                    throw;
                }
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(exception);
            }
            return(runtime2);
        }
Exemplo n.º 29
0
        internal ImmutableDispatchRuntime(DispatchRuntime dispatch)
        {
            _concurrency = new ConcurrencyBehavior(dispatch);
            _error = new ErrorBehavior(dispatch.ChannelDispatcher);
            _enableFaults = dispatch.EnableFaults;
            _instance = new InstanceBehavior(dispatch, this);
            _manualAddressing = dispatch.ManualAddressing;
            _thread = new ThreadBehavior(dispatch);
            _sendAsynchronously = dispatch.ChannelDispatcher.SendAsynchronously;
            _correlationCount = dispatch.MaxParameterInspectors;

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

            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;

            _processMessage1 = ProcessMessage1;
            _processMessage11 = ProcessMessage11;
            _processMessage2 = ProcessMessage2;
            _processMessage3 = ProcessMessage3;
            _processMessage31 = ProcessMessage31;
            _processMessage4 = ProcessMessage4;
            _processMessage41 = ProcessMessage41;
            _processMessage5 = ProcessMessage5;
            _processMessage6 = ProcessMessage6;
            _processMessage7 = ProcessMessage7;
            _processMessage8 = ProcessMessage8;
            _processMessage9 = ProcessMessage9;
            _processMessageCleanup = ProcessMessageCleanup;
            _processMessageCleanupError = ProcessMessageCleanupError;
        }
Exemplo n.º 30
0
 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);
     }
 }
        internal ImmutableDispatchRuntime(DispatchRuntime dispatch)
        {
            this.authenticationBehavior = AuthenticationBehavior.TryCreate(dispatch);
            this.authorizationBehavior = AuthorizationBehavior.TryCreate(dispatch);
            this.concurrency = new ConcurrencyBehavior(dispatch);
            this.error = new ErrorBehavior(dispatch.ChannelDispatcher);
            this.enableFaults = dispatch.EnableFaults;
            this.inputSessionShutdownHandlers = EmptyArray<IInputSessionShutdown>.ToArray(dispatch.InputSessionShutdownHandlers);
            this.instance = new InstanceBehavior(dispatch, this);
            this.isOnServer = dispatch.IsOnServer;
            this.manualAddressing = dispatch.ManualAddressing;
            this.messageInspectors = EmptyArray<IDispatchMessageInspector>.ToArray(dispatch.MessageInspectors);
            this.requestReplyCorrelator = new RequestReplyCorrelator();
            this.securityImpersonation = SecurityImpersonationBehavior.CreateIfNecessary(dispatch);
            this.requireClaimsPrincipalOnOperationContext = dispatch.RequireClaimsPrincipalOnOperationContext;
            this.impersonateOnSerializingReply = dispatch.ImpersonateOnSerializingReply;
            this.terminate = TerminatingOperationBehavior.CreateIfNecessary(dispatch);
            this.thread = new ThreadBehavior(dispatch);
            this.validateMustUnderstand = dispatch.ValidateMustUnderstand;
            this.ignoreTransactionFlow = dispatch.IgnoreTransactionMessageProperty;
            this.transaction = TransactionBehavior.CreateIfNeeded(dispatch);
            this.receiveContextEnabledChannel = dispatch.ChannelDispatcher.ReceiveContextEnabled;
            this.sendAsynchronously = dispatch.ChannelDispatcher.SendAsynchronously;
            this.parameterInspectorCorrelationOffset = (dispatch.MessageInspectors.Count +
                dispatch.MaxCallContextInitializers);
            this.correlationCount = this.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
            {
                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;
            }

            this.processMessage1 = new MessageRpcProcessor(this.ProcessMessage1);
            this.processMessage11 = new MessageRpcProcessor(this.ProcessMessage11);
            this.processMessage2 = new MessageRpcProcessor(this.ProcessMessage2);
            this.processMessage3 = new MessageRpcProcessor(this.ProcessMessage3);
            this.processMessage31 = new MessageRpcProcessor(this.ProcessMessage31);
            this.processMessage4 = new MessageRpcProcessor(this.ProcessMessage4);
            this.processMessage41 = new MessageRpcProcessor(this.ProcessMessage41);
            this.processMessage5 = new MessageRpcProcessor(this.ProcessMessage5);
            this.processMessage6 = new MessageRpcProcessor(this.ProcessMessage6);
            this.processMessage7 = new MessageRpcProcessor(this.ProcessMessage7);
            this.processMessage8 = new MessageRpcProcessor(this.ProcessMessage8);
            this.processMessage9 = new MessageRpcProcessor(this.ProcessMessage9);
            this.processMessageCleanup = new MessageRpcProcessor(this.ProcessMessageCleanup);
            this.processMessageCleanupError = new MessageRpcProcessor(this.ProcessMessageCleanupError);
        }
Exemplo n.º 32
0
        internal void AfterReply(ref ProxyRpc rpc)
        {
            if (!_isOneWay)
            {
                Message reply = rpc.Reply;

                if (_deserializeReply)
                {
                    if (WcfEventSource.Instance.ClientFormatterDeserializeReplyStartIsEnabled())
                    {
                        WcfEventSource.Instance.ClientFormatterDeserializeReplyStart(rpc.EventTraceActivity);
                    }

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

                    if (WcfEventSource.Instance.ClientFormatterDeserializeReplyStopIsEnabled())
                    {
                        WcfEventSource.Instance.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 (WcfEventSource.Instance.ClientParameterInspectorAfterCallInvokedIsEnabled())
                        {
                            WcfEventSource.Instance.ClientParameterInspectorAfterCallInvoked(rpc.EventTraceActivity, _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)));
                    }
                }
            }
        }
Exemplo n.º 33
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();
                        }
                    }
                    else if (releaseServiceInstanceOnTransactionComplete &&
                            this.isSynchronized &&
                            rpc.transaction != null &&
                            (rpc.transaction.IsCompleted || (rpc.Error != null)))
                    {
                        if (context.State == CommunicationState.Opened)
                        {
                            context.ReleaseServiceInstance();
                        }
                        if (DiagnosticUtility.ShouldTraceInformation)
                        {
                            TraceUtility.TraceEvent(TraceEventType.Information,
                                                                         TraceCode.TxReleaseServiceInstanceOnCompletion,
                                                                         SR.GetString(SR.TraceCodeTxReleaseServiceInstanceOnCompletion, "*"));
                        }
                    }
                }
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }
                    error.HandleError(e);
                }

                try
                {
                    context.UnbindRpc(ref rpc);
                }
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }
                    error.HandleError(e);
                }
            }
        }
Exemplo n.º 34
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.GetString(SR.TraceCodeUnhandledAction),
                                            new StringTraceRecord("Action", action),
                                            this, null, message);
                }

                FaultCode code = FaultCode.CreateSenderFaultCode(AddressingStrings.ActionNotSupported,
                                                                 message.Version.Addressing.Namespace);
                string      reasonText = SR.GetString(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 = this.dispatchRuntime.ChannelDispatcher;
                    if (!channelDispatcher.HandleError(exception) && serviceChannel.HasSession)
                    {
                        try
                        {
                            serviceChannel.Close(ChannelHandler.CloseAfterFaultTimeout);
                        }
                        catch (Exception ex)
                        {
                            if (Fx.IsFatal(ex))
                            {
                                throw;
                            }
                            channelDispatcher.HandleError(ex);
                        }
                    }
                };

                if (this.dispatchRuntime.shared.EnableFaults)
                {
                    MessageFault fault = MessageFault.CreateFault(code, reason, action);
                    return(Message.CreateMessage(message.Version, fault, message.Version.Addressing.DefaultFaultAction));
                }
                else
                {
                    OperationContext.Current.RequestContext.Close();
                    OperationContext.Current.RequestContext = null;
                    return(null);
                }
            }
Exemplo n.º 35
0
        void SerializeOutputs(ref MessageRpc rpc)
        {
            if (!this.IsOneWay && _parent.EnableFaults)
            {
                Message reply;
                if (_serializeReply)
                {
                    if (TD.DispatchFormatterSerializeReplyStartIsEnabled())
                    {
                        TD.DispatchFormatterSerializeReplyStart(rpc.EventTraceActivity);
                    }

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

                    if (TD.DispatchFormatterSerializeReplyStopIsEnabled())
                    {
                        TD.DispatchFormatterSerializeReplyStop(rpc.EventTraceActivity);
                    }

                    if (reply == null)
                    {
                        string message = SR.Format(SR.SFxNullReplyFromFormatter2, this.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, this.ReplyAction)))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.SFxInvalidReplyAction, this.Name, reply.Headers.Action ?? "{NULL}", this.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);
                        }
                    }
                }

                if (MessageLogger.LoggingEnabled && null != reply)
                {
                    MessageLogger.LogMessage(ref reply, MessageLoggingSource.ServiceLevelSendReply | MessageLoggingSource.LastChance);
                }
                rpc.Reply = reply;
            }
        }