internal ImmutableClientRuntime(ClientRuntime behavior)
        {
            _channelInitializers = EmptyArray<IChannelInitializer>.ToArray(behavior.ChannelInitializers);
            _interactiveChannelInitializers = EmptyArray<IInteractiveChannelInitializer>.ToArray(behavior.InteractiveChannelInitializers);
            _messageInspectors = EmptyArray<IClientMessageInspector>.ToArray(behavior.MessageInspectors);

            _operationSelector = behavior.OperationSelector;
            _useSynchronizationContext = behavior.UseSynchronizationContext;
            _validateMustUnderstand = behavior.ValidateMustUnderstand;

            _unhandled = new ProxyOperationRuntime(behavior.UnhandledClientOperation, this);

            _addTransactionFlowProperties = behavior.AddTransactionFlowProperties;

            _operations = new Dictionary<string, ProxyOperationRuntime>();

            for (int i = 0; i < behavior.Operations.Count; i++)
            {
                ClientOperation operation = behavior.Operations[i];
                ProxyOperationRuntime operationRuntime = new ProxyOperationRuntime(operation, this);
                _operations.Add(operation.Name, operationRuntime);
            }

            _correlationCount = _messageInspectors.Length + behavior.MaxParameterInspectors;
        }
        internal ProxyOperationRuntime GetOperationByName(string operationName)
        {
            ProxyOperationRuntime runtime = null;

            if (this.operations.TryGetValue(operationName, out runtime))
            {
                return(runtime);
            }
            return(null);
        }
Exemple #3
0
        internal ProxyOperationRuntime GetOperationByName(string operationName)
        {
            ProxyOperationRuntime operation = null;

            if (_operations.TryGetValue(operationName, out operation))
            {
                return(operation);
            }
            else
            {
                return(null);
            }
        }
 internal ProxyRpc(ServiceChannel channel, ProxyOperationRuntime operation, string action, object[] inputs, TimeSpan timeout)
 {
     this.Action = action;
     this.Activity = null;
     this.Channel = channel;
     this.Correlation = EmptyArray.Allocate(operation.Parent.CorrelationCount);
     this.InputParameters = inputs;
     this.Operation = operation;
     this.OutputParameters = null;
     this.Request = null;
     this.Reply = null;
     this.ActivityId = Guid.Empty;
     this.ReturnValue = null;
     this.MessageVersion = channel.MessageVersion;
     this.TimeoutHelper = new System.Runtime.TimeoutHelper(timeout);
 }
 internal ProxyRpc(ServiceChannel channel, ProxyOperationRuntime operation, string action, object[] inputs, TimeSpan timeout)
 {
     this.Action           = action;
     this.Activity         = null;
     this.Channel          = channel;
     this.Correlation      = EmptyArray.Allocate(operation.Parent.CorrelationCount);
     this.InputParameters  = inputs;
     this.Operation        = operation;
     this.OutputParameters = null;
     this.Request          = null;
     this.Reply            = null;
     this.ActivityId       = Guid.Empty;
     this.ReturnValue      = null;
     this.MessageVersion   = channel.MessageVersion;
     this.TimeoutHelper    = new System.Runtime.TimeoutHelper(timeout);
 }
        internal ProxyRpc(ServiceChannel channel, ProxyOperationRuntime operation, string action, object[] inputs, TimeSpan timeout)
        {
            Action              = action;
            Activity            = null;
            _eventTraceActivity = null;
            Channel             = channel;
            Correlation         = EmptyArray <object> .Allocate(operation.Parent.CorrelationCount);

            InputParameters  = inputs;
            Operation        = operation;
            OutputParameters = null;
            Request          = null;
            Reply            = null;
            ActivityId       = Guid.Empty;
            ReturnValue      = null;
            MessageVersion   = channel.MessageVersion;
            TimeoutHelper    = new TimeoutHelper(timeout);
        }
        internal ImmutableClientRuntime(ClientRuntime behavior)
        {
            this.channelInitializers = EmptyArray <IChannelInitializer> .ToArray(behavior.ChannelInitializers);

            this.interactiveChannelInitializers = EmptyArray <IInteractiveChannelInitializer> .ToArray(behavior.InteractiveChannelInitializers);

            this.messageInspectors = EmptyArray <IClientMessageInspector> .ToArray(behavior.MessageInspectors);

            this.operationSelector         = behavior.OperationSelector;
            this.useSynchronizationContext = behavior.UseSynchronizationContext;
            this.validateMustUnderstand    = behavior.ValidateMustUnderstand;
            this.unhandled = new ProxyOperationRuntime(behavior.UnhandledClientOperation, this);
            this.addTransactionFlowProperties = behavior.AddTransactionFlowProperties;
            this.operations = new Dictionary <string, ProxyOperationRuntime>();
            for (int i = 0; i < behavior.Operations.Count; i++)
            {
                ClientOperation       operation = behavior.Operations[i];
                ProxyOperationRuntime runtime   = new ProxyOperationRuntime(operation, this);
                this.operations.Add(operation.Name, runtime);
            }
            this.correlationCount = this.messageInspectors.Length + behavior.MaxParameterInspectors;
        }
Exemple #8
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;
            }
        }
 public MethodData(System.Reflection.MethodBase methodBase, System.ServiceModel.Channels.ServiceChannelProxy.MethodType methodType, ProxyOperationRuntime operation)
 {
     this.methodBase = methodBase;
     this.methodType = methodType;
     this.operation = operation;
 }
 private IMethodReturnMessage InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
 {
     object[] objArray;
     object[] ins = operation.MapSyncInputs(methodCall, out objArray);
     object ret = this.serviceChannel.Call(operation.Action, operation.IsOneWay, operation, ins, objArray);
     object[] returnArgs = operation.MapSyncOutputs(methodCall, objArray, ref ret);
     return this.CreateReturnMessage(ret, returnArgs, methodCall);
 }
 private IMethodReturnMessage InvokeEndService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
 {
     IAsyncResult result;
     object[] objArray;
     operation.MapAsyncEndInputs(methodCall, out result, out objArray);
     object ret = this.serviceChannel.EndCall(operation.Action, objArray, result);
     object[] returnArgs = operation.MapAsyncOutputs(methodCall, objArray, ref ret);
     return this.CreateReturnMessage(ret, returnArgs, methodCall);
 }
 private IMethodReturnMessage InvokeBeginService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
 {
     AsyncCallback callback;
     object obj2;
     object[] ins = operation.MapAsyncBeginInputs(methodCall, out callback, out obj2);
     object ret = this.serviceChannel.BeginCall(operation.Action, operation.IsOneWay, operation, ins, callback, obj2);
     return this.CreateReturnMessage(ret, null, methodCall);
 }
Exemple #13
0
 private void SerializeOutputs(ref MessageRpc rpc)
 {
     if (!this.IsOneWay && this.parent.EnableFaults)
     {
         Message returnParameter;
         if (this.serializeReply)
         {
             try
             {
                 returnParameter = this.Formatter.SerializeReply(rpc.RequestVersion, rpc.OutputParameters, rpc.ReturnParameter);
             }
             catch (Exception exception)
             {
                 if (Fx.IsFatal(exception))
                 {
                     throw;
                 }
                 if (ErrorBehavior.ShouldRethrowExceptionAsIs(exception))
                 {
                     throw;
                 }
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(exception);
             }
             if (returnParameter == null)
             {
                 object[] args = new object[] { this.Formatter.GetType().ToString(), this.name ?? "" };
                 ErrorBehavior.ThrowAndCatch(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxNullReplyFromFormatter2", args)));
             }
         }
         else
         {
             if ((rpc.ReturnParameter == null) && (rpc.OperationContext.RequestContext != null))
             {
                 ErrorBehavior.ThrowAndCatch(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxDispatchRuntimeMessageCannotBeNull", new object[] { this.name })));
             }
             returnParameter = (Message)rpc.ReturnParameter;
             if ((returnParameter != null) && !ProxyOperationRuntime.IsValidAction(returnParameter, this.ReplyAction))
             {
                 object[] objArray3 = new object[] { this.Name, returnParameter.Headers.Action ?? "{NULL}", this.ReplyAction };
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxInvalidReplyAction", objArray3)));
             }
         }
         if ((DiagnosticUtility.ShouldUseActivity && (rpc.Activity != null)) && (returnParameter != null))
         {
             TraceUtility.SetActivity(returnParameter, rpc.Activity);
             if (TraceUtility.ShouldPropagateActivity)
             {
                 TraceUtility.AddActivityHeader(returnParameter);
             }
         }
         else if ((TraceUtility.ShouldPropagateActivity && (returnParameter != null)) && (rpc.ResponseActivityId != Guid.Empty))
         {
             new ActivityIdHeader(rpc.ResponseActivityId).AddTo(returnParameter);
         }
         if (TraceUtility.MessageFlowTracingOnly)
         {
             if ((rpc.OperationContext.IncomingMessage != null) && (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 && (returnParameter != null))
         {
             MessageLogger.LogMessage(ref returnParameter, MessageLoggingSource.LastChance | MessageLoggingSource.ServiceLevelSendReply);
         }
         rpc.Reply = returnParameter;
     }
 }
        void SerializeOutputs(ref MessageRpc rpc)
        {
            if (!this.IsOneWay && this.parent.EnableFaults)
            {
                Message reply;
                if (this.serializeReply)
                {
                    try
                    {
                        if (TD.DispatchFormatterSerializeReplyStartIsEnabled())
                        {
                            TD.DispatchFormatterSerializeReplyStart(rpc.EventTraceActivity);
                        }

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

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

                        if (outputTiming)
                        {
                            DS.DispatchMessageFormatterSerialize(this.Formatter.GetType(), sw.Elapsed);
                        }

                        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.GetString(SR.SFxNullReplyFromFormatter2, this.Formatter.GetType().ToString(), (this.name ?? ""));
                        ErrorBehavior.ThrowAndCatch(new InvalidOperationException(message));
                    }
                }
                else
                {
                    if ((rpc.ReturnParameter == null) && (rpc.OperationContext.RequestContext != null))
                    {
                        string message = SR.GetString(SR.SFxDispatchRuntimeMessageCannotBeNull, this.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.GetString(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);
                        }
                    }
                }

                // 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;
            }
        }