public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
		{
			foreach (DispatchOperation operation in endpointDispatcher.DispatchRuntime.Operations)
			{
				operation.CallContextInitializers.Add(new UnitOfWorkCallContextInitializer());
			}
		}
Ejemplo n.º 2
0
 /// <summary>
 ///     This service modify or extend the service across an endpoint.
 /// </summary>
 /// <param name="endpoint">The endpoint that exposes the contract.</param>
 /// <param name="endpointDispatcher">
 ///     The endpoint dispatcher to be
 ///     modified or extended.
 /// </param>
 public void ApplyDispatchBehavior(ServiceEndpoint endpoint,
     EndpointDispatcher endpointDispatcher)
 {
     // add inspector which detects cross origin requests
     endpointDispatcher.DispatchRuntime.MessageInspectors.Add(
         new MessageInspector(endpoint));
 }
Ejemplo n.º 3
0
 public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
 {
     foreach (var operation in endpoint.Contract.Operations)
     {
         DecorateFormatterBehavior(operation, endpointDispatcher.DispatchRuntime);
     }
 }
 public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
 {
     foreach (var operation in endpointDispatcher.DispatchRuntime.Operations)
     {
         operation.CallContextInitializers.Add(_callContextInitializer);
     }
 }
 public void ApplyDispatchBehavior(ServiceEndpoint Endpoint, EndpointDispatcher EndpointDispatcher)
     {
     return;
     //EndpointDispatcher.DispatchRuntime.MessageInspectors.Add (new HeaderInsertClientMessageInspector ());
     //foreach (DispatchOperation op in EndpointDispatcher.DispatchRuntime.Operations)
     //    op.ParameterInspectors.Add (new HeaderInsertClientMessageInspector ());
     }
        private static void CreateHttpGetChannelDispatcher(ServiceHostBase host, Uri listenUri, MetadataSet metadata)
        {
            //创建Binding
            TextMessageEncodingBindingElement messageEncodingElement = new TextMessageEncodingBindingElement() { MessageVersion = MessageVersion.None };
            HttpTransportBindingElement transportElement = new HttpTransportBindingElement();
            Utility.SetPropertyValue(transportElement, "Method", "GET");
            Binding binding = new CustomBinding(messageEncodingElement, transportElement);

            //创建ChannelListener
            IChannelListener listener = binding.BuildChannelListener<IReplyChannel>(listenUri, string.Empty, ListenUriMode.Explicit, new BindingParameterCollection());
            ChannelDispatcher dispatcher = new ChannelDispatcher(listener, "ServiceMetadataBehaviorHttpGetBinding", binding) { MessageVersion = binding.MessageVersion };

            //创建EndpointDispatcher
            EndpointDispatcher endpoint = new EndpointDispatcher(new EndpointAddress(listenUri), "IHttpGetMetadata", "http://www.artech.com/");

            //创建DispatchOperation,并设置DispatchMessageFormatter和OperationInvoker
            DispatchOperation operation = new DispatchOperation(endpoint.DispatchRuntime, "Get", "*", "*");
            operation.Formatter = Utility.CreateInstance<IDispatchMessageFormatter>(MessageOperationFormatterType, Type.EmptyTypes, new object[0]);
            MethodInfo method = typeof(IHttpGetMetadata).GetMethod("Get");
            operation.Invoker = Utility.CreateInstance<IOperationInvoker>(SyncMethodInvokerType, new Type[] { typeof(MethodInfo) }, new object[] { method });
            endpoint.DispatchRuntime.Operations.Add(operation);

            //设置SingletonInstanceContext和InstanceContextProvider
            MetadataProvisionService serviceInstance = new MetadataProvisionService(metadata);
            endpoint.DispatchRuntime.SingletonInstanceContext = new InstanceContext(host, serviceInstance);
            endpoint.DispatchRuntime.InstanceContextProvider = Utility.CreateInstance<IInstanceContextProvider>(SingletonInstanceContextProviderType, new Type[] { typeof(DispatchRuntime) }, new object[] { endpoint.DispatchRuntime });
            dispatcher.Endpoints.Add(endpoint);

            //设置ContractFilter和AddressFilter
            endpoint.ContractFilter = new MatchAllMessageFilter();
            endpoint.AddressFilter = new MatchAllMessageFilter();

            host.ChannelDispatchers.Add(dispatcher);
        }
 void IEndpointBehavior.ApplyDispatchBehavior(ServiceEndpoint serviceEndpoint, EndpointDispatcher endpointDispatcher)
 {
     if (endpointDispatcher.DispatchRuntime.ReleaseServiceInstanceOnTransactionComplete)
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxNoBatchingForReleaseOnComplete)));
     if (serviceEndpoint.Contract.SessionMode == SessionMode.Required)
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxNoBatchingForSession)));
 }
        public void ApplyDispatchBehavior(ServiceEndpoint serviceEndpoint, EndpointDispatcher endpointDispatcher)
        {
            if (serviceEndpoint == null)
                throw new ArgumentNullException("serviceEndpoint");

            if (endpointDispatcher == null)
                throw new ArgumentNullException("endpointDispatcher");

            // Apply URI-based operation selector
            Dictionary<string, string> operationNameDictionary = new Dictionary<string, string>();
            foreach (OperationDescription operation in serviceEndpoint.Contract.Operations)
            {
                try
                {
                    operationNameDictionary.Add(operation.Name.ToLower(), operation.Name);
                }
                catch (ArgumentException)
                {
                    throw new Exception(String.Format("The specified contract cannot be used with case insensitive URI dispatch because there is more than one operation named {0}", operation.Name));
                }
            }
            endpointDispatcher.AddressFilter = new PrefixEndpointAddressMessageFilter(serviceEndpoint.Address);
            endpointDispatcher.ContractFilter = new MatchAllMessageFilter();
            endpointDispatcher.DispatchRuntime.OperationSelector = new UriPathSuffixOperationSelector(serviceEndpoint.Address.Uri, operationNameDictionary);
        }
 public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
 {
     foreach (var item in endpointDispatcher.DispatchRuntime.Operations)
     {
         item.CallContextInitializers.Add(new CultureSettingCallContextInitializer());
     }
 }
 public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
 {
     foreach (var operation in endpoint.Contract.Operations.Where(o => Methods.Contains(o.Name)))
     {
         operation.Behaviors.Find<DataContractSerializerOperationBehavior>().DataContractSurrogate = new JavascriptCallbackSurrogate(callbackFactory);
     }
 }
 public void AddEndpoint(EndpointDispatcher endpoint)
 {
     lock (this.ThisLock)
     {
         MessageFilter endpointFilter = endpoint.EndpointFilter;
         int filterPriority = endpoint.FilterPriority;
         if (this.filters == null)
         {
             if (this.cachedEndpoints == null)
             {
                 this.cachedEndpoints = new List<EndpointDispatcher>(2);
             }
             if (this.cachedEndpoints.Count < 2)
             {
                 this.cachedEndpoints.Add(endpoint);
             }
             else
             {
                 this.filters = new MessageFilterTable<EndpointDispatcher>();
                 for (int i = 0; i < this.cachedEndpoints.Count; i++)
                 {
                     int priority = this.cachedEndpoints[i].FilterPriority;
                     MessageFilter filter = this.cachedEndpoints[i].EndpointFilter;
                     this.filters.Add(filter, this.cachedEndpoints[i], priority);
                 }
                 this.filters.Add(endpointFilter, endpoint, filterPriority);
                 this.cachedEndpoints = null;
             }
         }
         else
         {
             this.filters.Add(endpointFilter, endpoint, filterPriority);
         }
     }
 }
Ejemplo n.º 12
0
 void IEndpointBehavior.ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
 {
     WsdlExporter wsdlExporter = new WsdlExporter();
     wsdlExporter.ExportEndpoint(endpoint);
     endpointDispatcher.DispatchRuntime.MessageInspectors.Add(
         new XsdValidationInspector(wsdlExporter.GeneratedXmlSchemas));
 }
 public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
 {
     foreach (var operation in endpointDispatcher.DispatchRuntime.Operations)
     {
         operation.CallContextInitializers.Add(new ApplicationContextCallContextInitializer(this.IsBidirectional, this.SessionCheck));
     }
 }
Ejemplo n.º 14
0
 public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
 {
     List<OperationDescription> corsEnabledOperations = endpoint.Contract.Operations
         .Where(o => o.Behaviors.Find<CorsEnabledAttribute>() != null)
         .ToList();
     endpointDispatcher.DispatchRuntime.MessageInspectors.Add(new CorsEnabledMessageInspector(corsEnabledOperations));
 }
 public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
 {
     foreach (DispatchOperation operation in endpointDispatcher.DispatchRuntime.Operations)
     {
         operation.ParameterInspectors.Add(new OperationProfilerParameterInspector(this.manager, operation.IsOneWay));
     }
 }
        public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
        {
            var protoBinding = endpoint.Binding as ProtoBufBinding;

            if (protoBinding == null)
                throw new ConfigurationException("The endpoint behaviour, ProtoBufBindingEndpointBehaviour, can only be applied to an endpoint which has ProtoBufBinding as its binding.");

            foreach (var operation in endpointDispatcher.DispatchRuntime.Operations)
            {
                var compressionBehaviour = protoBinding.GetOperationCompressionBehaviour(operation.Name);

                var contractInfo = ContractInfo.FromAction(operation.Action);

                var serviceContract = TypeFinder.FindServiceContract(contractInfo.ServiceContractName);

                var paramTypes = TypeFinder.GetContractParamTypes(serviceContract, contractInfo.OperationContractName,
                                                                  contractInfo.Action, false);

                var formatter = new ProtoBufDispatchFormatter(new List<TypeInfo>(paramTypes), contractInfo.Action, 
                    compressionBehaviour);

                operation.Formatter = formatter;
                operation.DeserializeRequest = true;
                operation.SerializeReply = true;
            }
        }
Ejemplo n.º 17
0
 public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
 {
     foreach (var op in endpoint.Contract.Operations)
     {
         op.Behaviors.Add(this);
     }
 }
 public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
 {
     foreach (DispatchOperation operation in endpointDispatcher.DispatchRuntime.Operations)
     {
         operation.ParameterInspectors.Add(new ConsumerInspector());
     }
 }
        void IEndpointBehavior.ApplyDispatchBehavior(ServiceEndpoint serviceEndpoint, EndpointDispatcher endpointDispatcher)
        {
            if (endpointDispatcher == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("endpointDispatcher"));

            endpointDispatcher.DispatchRuntime.ValidateMustUnderstand = this.ValidateMustUnderstand;
        }
Ejemplo n.º 20
0
		public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
		{
			foreach (var errorHandler in errorHandlers)
			{
				endpointDispatcher.ChannelDispatcher.ErrorHandlers.Add(errorHandler);
			}
		}
        EndpointDispatcher(EndpointDispatcher baseEndpoint, IEnumerable<AddressHeader> headers)
        {
            EndpointAddressBuilder builder = new EndpointAddressBuilder(baseEndpoint.EndpointAddress);
            foreach (AddressHeader h in headers)
            {
                builder.Headers.Add(h);
            }
            EndpointAddress address = builder.ToEndpointAddress();

            this.addressFilter = new EndpointAddressMessageFilter(address);
            // channelDispatcher is Attached
            this.contractFilter = baseEndpoint.ContractFilter;
            this.contractName = baseEndpoint.ContractName;
            this.contractNamespace = baseEndpoint.ContractNamespace;
            this.dispatchRuntime = baseEndpoint.DispatchRuntime;
            // endpointFilter is lazy
            this.filterPriority = baseEndpoint.FilterPriority + 1;
            this.originalAddress = address;
            if (PerformanceCounters.PerformanceCountersEnabled)
            {
                this.perfCounterId = baseEndpoint.perfCounterId;
                this.perfCounterBaseId = baseEndpoint.perfCounterBaseId;
            }
            this.id = baseEndpoint.id;
        }
 void IEndpointBehavior.ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher dispatcher)
 {
     //if (s_Logger.IsDebugEnabled)
     //{
     //    s_Logger.DebugFormat("Applying dispatch ExceptionMarshallingBehavior to endpoint {0}", endpoint.Address);
     //}
     ApplyDispatchBehavior(dispatcher.ChannelDispatcher);
 }
        public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
        {
            endpointDispatcher.ChannelDispatcher.ErrorHandlers.Add(new ErrorHandler());
            //if (_messageInspectors.Any())
            //    endpointDispatcher.AddMessageInspectors(_messageInspectors);

            //base.ApplyDispatchBehavior(endpoint, endpointDispatcher);
        }
        /// <summary>
        /// Override this method to change the way errors that occur on the service are handled.
        /// </summary>
        /// <param name="endpoint">The service endpoint.</param>
        /// <param name="endpointDispatcher">The endpoint dispatcher.</param>
        protected override void AddServerErrorHandlers(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
        {
            // Clear default error handlers
            endpointDispatcher.ChannelDispatcher.ErrorHandlers.Clear();

            // Add the JSON error handler
            endpointDispatcher.ChannelDispatcher.ErrorHandlers.Add(new JsonFaultHandler());
        }
Ejemplo n.º 25
0
 public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
 {
     endpointDispatcher.ChannelDispatcher.ErrorHandlers.Add(new ValidationAwareErrorHandler());
     foreach (DispatchOperation op in endpointDispatcher.DispatchRuntime.Operations)
     {
         op.ParameterInspectors.Add(new ValidatingParameterInspector());
     }
 }
Ejemplo n.º 26
0
        void IEndpointBehavior.ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
        {
            var inspector = new WcfProfilingDispatchMessageInspector();
            endpointDispatcher.DispatchRuntime.MessageInspectors.Add(inspector);

            var errorHandler = new WcfProfilingErrorHandler();
            endpointDispatcher.ChannelDispatcher.ErrorHandlers.Add(errorHandler);
        }
Ejemplo n.º 27
0
		public DuplexClientRuntimeChannel (ServiceEndpoint endpoint,
			ChannelFactory factory, EndpointAddress remoteAddress, Uri via)
			: base (endpoint, factory, remoteAddress, via)
		{
			var ed = new EndpointDispatcher (remoteAddress, endpoint.Contract.Name, endpoint.Contract.Namespace);
			ed.InitializeServiceEndpoint (true, null, endpoint);
			Runtime.CallbackDispatchRuntime = ed.DispatchRuntime;
		}
 void IEndpointBehavior.ApplyDispatchBehavior(ServiceEndpoint serviceEndpoint, EndpointDispatcher endpointDispatcher)
 {
     if (endpointDispatcher == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("endpointDispatcher");
     }
     endpointDispatcher.ChannelDispatcher.ReceiveSynchronously = true;
 }
 public override void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
 {
     base.ApplyDispatchBehavior(endpoint, endpointDispatcher);
     foreach (DispatchOperation operation in endpointDispatcher.DispatchRuntime.Operations)
     {
         operation.ParameterInspectors.Add(new ValidatingParameterInspector());
     }
 }
 public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
 {
     foreach (var operation in endpointDispatcher.DispatchRuntime.Operations)
     {
         operation.CallContextInitializers.Add(
             new OperationTimingCallContextInitializer(_invocationReporter, operation.Name, endpoint.Contract.Name));
     }
 }
Ejemplo n.º 31
0
 public void ApplyDispatchBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
 {
     endpointDispatcher.AddressFilter  = _addressFilter;
     endpointDispatcher.ContractFilter = _contractFilter;
 }
 //Shared
 public void ApplyDispatchBehavior(System.ServiceModel.Description.ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
 {
 }
 /// <summary>
 /// Implements a modification or extension of the service across an endpoint. The current implementation does nothing.
 /// </summary>
 /// <param name="endpoint">The endpoint that is to be customized.</param>
 /// <param name="endpointDispatcher">The endpoint dispatcher to be modified or extended.</param>
 public void ApplyDispatchBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
 {
     // Leave empty, do nothing
 }
Ejemplo n.º 34
0
        private bool DispatchAndReleasePump(RequestContext request, bool cleanThread, OperationContext currentOperationContext)
        {
            ServiceChannel     channel  = _requestInfo.Channel;
            EndpointDispatcher endpoint = _requestInfo.Endpoint;
            bool releasedPump           = false;

            try
            {
                DispatchRuntime dispatchBehavior = _requestInfo.DispatchRuntime;

                if (channel == null || dispatchBehavior == null)
                {
                    Fx.Assert("System.ServiceModel.Dispatcher.ChannelHandler.Dispatch(): (channel == null || dispatchBehavior == null)");
                    return(true);
                }

                EventTraceActivity eventTraceActivity = TraceDispatchMessageStart(request.RequestMessage);
                Message            message            = request.RequestMessage;

                DispatchOperationRuntime operation = dispatchBehavior.GetOperation(ref message);
                if (operation == null)
                {
                    Fx.Assert("ChannelHandler.Dispatch (operation == null)");
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, "No DispatchOperationRuntime found to process message.")));
                }

                if (_shouldRejectMessageWithOnOpenActionHeader && message.Headers.Action == OperationDescription.SessionOpenedAction)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.SFxNoEndpointMatchingAddressForConnectionOpeningMessage, message.Headers.Action, "Open")));
                }

                if (MessageLogger.LoggingEnabled)
                {
                    MessageLogger.LogMessage(ref message, (operation.IsOneWay ? MessageLoggingSource.ServiceLevelReceiveDatagram : MessageLoggingSource.ServiceLevelReceiveRequest) | MessageLoggingSource.LastChance);
                }

                bool hasOperationContextBeenSet;
                if (currentOperationContext != null)
                {
                    hasOperationContextBeenSet = true;
                    currentOperationContext.ReInit(request, message, channel);
                }
                else
                {
                    hasOperationContextBeenSet = false;
                    currentOperationContext    = new OperationContext(request, message, channel);
                }

                MessageRpc rpc = new MessageRpc(request, message, operation, channel,
                                                this, cleanThread, currentOperationContext, _requestInfo.ExistingInstanceContext, eventTraceActivity);

                TraceUtility.MessageFlowAtMessageReceived(message, currentOperationContext, eventTraceActivity, true);

                // These need to happen before Dispatch but after accessing any ChannelHandler
                // state, because we go multi-threaded after this until we reacquire pump mutex.
                ReleasePump();
                releasedPump = true;

                return(operation.Parent.Dispatch(ref rpc, hasOperationContextBeenSet));
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                return(this.HandleError(e, request, channel));
            }
            finally
            {
                if (!releasedPump)
                {
                    this.ReleasePump();
                }
            }
        }
Ejemplo n.º 35
0
 public void ApplyDispatchBehavior(System.ServiceModel.Description.ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
 {
     AddInspectorToEndPoint(ref endpointDispatcher);
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="endpoint"></param>
        /// <param name="endpointDispatcher"></param>
        public void ApplyDispatchBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
        {
            IErrorHandler handler = new ValidateFaultHandler( );

            endpointDispatcher.ChannelDispatcher.ErrorHandlers.Add(handler);
        }
Ejemplo n.º 37
0
 public void ApplyDispatchBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
 {
     throw new Exception("Behavior not supported on the consumer side!");
 }
Ejemplo n.º 38
0
 public void ApplyDispatchBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
 {
     //     throw new NotImplementedException();
 }
Ejemplo n.º 39
0
        public void ApplyDispatchBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
        {
            ConsoleOutputMessageInspector inspector = new ConsoleOutputMessageInspector();

            endpointDispatcher.DispatchRuntime.MessageInspectors.Add(inspector);
        }
Ejemplo n.º 40
0
 internal DispatchRuntime(EndpointDispatcher dispatcher, ClientRuntime callbackClientRuntime)
 {
     UnhandledDispatchOperation = new DispatchOperation(
         this, "*", "*", "*");
 }
Ejemplo n.º 41
0
        public void ApplyDispatchBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
        {
            SilverlightFaultMessageInspector inspector = new SilverlightFaultMessageInspector();

            endpointDispatcher.DispatchRuntime.MessageInspectors.Add(inspector);
        }
 public void ApplyDispatchBehavior(ServiceEndpoint serviceEndpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
 {
 }
Ejemplo n.º 43
0
 /// <summary>
 /// Aplica o comportamento do despachante das mensagens.
 /// </summary>
 /// <param name="endpoint"></param>
 /// <param name="endpointDispatcher"></param>
 public void ApplyDispatchBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
 {
     endpointDispatcher.DispatchRuntime.MessageInspectors.Add(CreateMessageInspector());
 }
 void IEndpointBehavior.ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
 {
 }
Ejemplo n.º 45
0
 protected override void AddServerErrorHandlers(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
 {
     endpointDispatcher.ChannelDispatcher.ErrorHandlers.Add(new WfErrorHandler());
 }
        public Message Request(Message message, TimeSpan timeout)
        {
            SyncDuplexRequest request = null;
            bool flag = false;

            RequestReplyCorrelator.PrepareRequest(message);
            lock (this.ThisLock)
            {
                if (!this.Pumping)
                {
                    flag = true;
                    this.syncPumpEnabled = true;
                }
                if (!flag)
                {
                    request = new SyncDuplexRequest(this);
                }
                this.RequestStarting(message, request);
            }
            if (flag)
            {
                TimeoutHelper helper    = new TimeoutHelper(timeout);
                UniqueId      messageId = message.Headers.MessageId;
                try
                {
                    this.channel.Send(message, helper.RemainingTime());
                    if ((DiagnosticUtility.ShouldUseActivity && (ServiceModelActivity.Current != null)) && (ServiceModelActivity.Current.ActivityType == ActivityType.ProcessAction))
                    {
                        ServiceModelActivity.Current.Suspend();
                    }
                    while (true)
                    {
                        Message  message2;
                        TimeSpan span = helper.RemainingTime();
                        if (!this.channel.TryReceive(span, out message2))
                        {
                            throw TraceUtility.ThrowHelperError(this.GetReceiveTimeoutException(timeout), message);
                        }
                        if (message2 == null)
                        {
                            this.AbortRequests();
                            return(null);
                        }
                        if (message2.Headers.RelatesTo == messageId)
                        {
                            this.ThrowIfInvalidReplyIdentity(message2);
                            return(message2);
                        }
                        if (!this.HandleRequestAsReply(message2))
                        {
                            if (DiagnosticUtility.ShouldTraceInformation)
                            {
                                EndpointDispatcher endpointDispatcher = null;
                                if ((this.ChannelHandler != null) && (this.ChannelHandler.Channel != null))
                                {
                                    endpointDispatcher = this.ChannelHandler.Channel.EndpointDispatcher;
                                }
                                TraceUtility.TraceDroppedMessage(message2, endpointDispatcher);
                            }
                            message2.Close();
                        }
                    }
                }
                finally
                {
                    lock (this.ThisLock)
                    {
                        this.RequestCompleting(null);
                        this.syncPumpEnabled = false;
                        if (this.pending > 0)
                        {
                            this.EnsurePumping();
                        }
                    }
                }
            }
            TimeoutHelper helper2 = new TimeoutHelper(timeout);

            this.channel.Send(message, helper2.RemainingTime());
            this.EnsurePumping();
            return(request.WaitForReply(helper2.RemainingTime()));
        }
Ejemplo n.º 47
0
 void IEndpointBehavior.ApplyDispatchBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
 {
 }