Beispiel #1
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);
            }
        }
        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);
            }
        }
Beispiel #3
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);
            }
        }
        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);
            }
        }
Beispiel #5
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)));
                }
            }
        }
Beispiel #6
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);
            }
        }
Beispiel #7
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);
            }
        }
Beispiel #8
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);
            }
        }
        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);
        }
Beispiel #10
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);
     }
 }
Beispiel #11
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)));
                    }
                }
            }
        }
Beispiel #12
0
        internal ProxyOperationRuntime GetOperation(MethodBase methodBase, object[] args, out bool canCacheResult)
        {
            if (this.operationSelector == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException
                                                                              (SR.GetString(SR.SFxNeedProxyBehaviorOperationSelector2,
                                                                                            methodBase.Name,
                                                                                            methodBase.DeclaringType.Name)));
            }

            try
            {
                if (operationSelector.AreParametersRequiredForSelection)
                {
                    canCacheResult = false;
                }
                else
                {
                    args           = null;
                    canCacheResult = true;
                }

                bool      outputTiming = DS.OperationSelectorIsEnabled();
                Stopwatch sw           = null;
                if (outputTiming)
                {
                    sw = Stopwatch.StartNew();
                }

                string operationName = operationSelector.SelectOperation(methodBase, args);

                if (outputTiming)
                {
                    DS.ClientSelectOperation(operationSelector.GetType(), operationName, sw.Elapsed);
                }

                ProxyOperationRuntime operation;
                if ((operationName != null) && this.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);
            }
        }
Beispiel #13
0
        internal void BeforeRequest(ref ProxyRpc rpc)
        {
            int offset = this.parent.ParameterInspectorCorrelationOffset;

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

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

                    rpc.Correlation[offset + i] = this.parameterInspectors[i].BeforeCall(this.name, rpc.InputParameters);
                    if (outputTiming)
                    {
                        DS.ParameterInspectorBefore(this.parameterInspectors[i].GetType(), sw.Elapsed);
                    }

                    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 (this.serializeRequest)
            {
                if (TD.ClientFormatterSerializeRequestStartIsEnabled())
                {
                    TD.ClientFormatterSerializeRequestStart(rpc.EventTraceActivity);
                }

                bool      outputTiming = DS.MessageFormatterIsEnabled();
                Stopwatch sw           = null;
                if (outputTiming)
                {
                    sw = Stopwatch.StartNew();
                }

                rpc.Request = this.formatter.SerializeRequest(rpc.MessageVersion, rpc.InputParameters);

                if (outputTiming)
                {
                    DS.ClientMessageFormatterSerialize(this.formatter.GetType(), sw.Elapsed);
                }

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

                rpc.Request = (Message)rpc.InputParameters[0];
                if (!IsValidAction(rpc.Request, Action))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxInvalidRequestAction, this.Name, rpc.Request.Headers.Action ?? "{NULL}", this.Action)));
                }
            }
        }
Beispiel #14
0
        internal void AfterReply(ref ProxyRpc rpc)
        {
            if (!this.isOneWay)
            {
                Message reply = rpc.Reply;

                if (this.deserializeReply)
                {
                    if (TD.ClientFormatterDeserializeReplyStartIsEnabled())
                    {
                        TD.ClientFormatterDeserializeReplyStart(rpc.EventTraceActivity);
                    }

                    bool      outputTiming = DS.MessageFormatterIsEnabled();
                    Stopwatch sw           = null;
                    if (outputTiming)
                    {
                        sw = Stopwatch.StartNew();
                    }

                    rpc.ReturnValue = this.formatter.DeserializeReply(reply, rpc.OutputParameters);

                    if (outputTiming)
                    {
                        DS.ClientMessageFormatterDeserialize(this.formatter.GetType(), sw.Elapsed);
                    }

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

                int offset = this.parent.ParameterInspectorCorrelationOffset;
                try
                {
                    bool      outputTiming = DS.ParameterInspectorIsEnabled();
                    Stopwatch sw           = null;
                    if (outputTiming)
                    {
                        sw = new Stopwatch();
                    }

                    for (int i = parameterInspectors.Length - 1; i >= 0; i--)
                    {
                        if (outputTiming)
                        {
                            sw.Restart();
                        }

                        this.parameterInspectors[i].AfterCall(this.name,
                                                              rpc.OutputParameters,
                                                              rpc.ReturnValue,
                                                              rpc.Correlation[offset + i]);
                        if (outputTiming)
                        {
                            DS.ParameterInspectorAfter(this.parameterInspectors[i].GetType(), sw.Elapsed);
                        }

                        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.GetString(SR.SFxHeaderNotUnderstood, headersNotUnderstood[0].Name, headersNotUnderstood[0].Namespace)));
                    }
                }
            }
        }