コード例 #1
0
        public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
        {
            Type serviceType = serviceDescription.ServiceType;

            serviceDescription.Endpoints.Add(endpoint);
            ChannelDispatcher dispatcher = CreateChannelDispatcher(endpoint, serviceType, actionMap);

            serviceHostBase.ChannelDispatchers.Add(dispatcher);
        }
コード例 #2
0
        protected void UnregisterListenerCommon(ChannelDispatcher channel, TimeSpan timeout)
        {
            lock (entries_lock) {
                var entry = Entries.First(e => e.ChannelDispatcher == channel);
                Entries.Remove(entry);

                entry.WaitHandle.Set();                  // make sure to finish pending requests.
            }
        }
コード例 #3
0
        public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
        {
            ChannelDispatcher d = serviceHostBase.ChannelDispatchers [0] as ChannelDispatcher;

            d.Endpoints [0].DispatchRuntime.MessageInspectors.Add(msgInspect);
            d.Endpoints [0].DispatchRuntime.InstanceContextProvider = instanceCtxProvider;
            d.Endpoints [0].DispatchRuntime.InstanceProvider        = instanceProvider;
            d.Endpoints [0].DispatchRuntime.InstanceContextInitializers.Add(instanceCtxInitializer);
        }
コード例 #4
0
 protected void UnregisterListenerCommon(ChannelDispatcher channel, TimeSpan timeout)
 {
     lock (entries_lock)
     {
         var entry = Entries.First(e => e.ChannelDispatcher == channel);
         Entries.Remove(entry);
         entry.WaitHandle.Set();
     }
 }
コード例 #5
0
        void IEndpointBehavior.ApplyClientBehavior(ServiceEndpoint serviceEndpoint, ClientRuntime behavior)
        {
            ChannelDispatcher channelDispatcher = behavior.CallbackDispatchRuntime.ChannelDispatcher;

            if (channelDispatcher != null && this.includeExceptionDetailInFaults)
            {
                channelDispatcher.IncludeExceptionDetailInFaults = true;
            }
        }
コード例 #6
0
        void SetIsolationLevel(ChannelDispatcher channelDispatcher)
        {
            if (channelDispatcher == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("channelDispatcher");
            }

            channelDispatcher.TransactionIsolationLevel = this.transactionIsolationLevel;
        }
コード例 #7
0
        void IServiceBehavior.ApplyDispatchBehavior(ServiceDescription description, ServiceHostBase serviceHostBase)
        {
            // Create an instance of the ObjectPoolInstanceProvider.
            ObjectPoolingInstanceProvider instanceProvider = new ObjectPoolingInstanceProvider(description.ServiceType,
                                                                                               minPoolSize);

            // Forward the call if we created a ServiceThrottlingBehavior.
            if (this.throttlingBehavior != null)
            {
                ((IServiceBehavior)this.throttlingBehavior).ApplyDispatchBehavior(description, serviceHostBase);
            }

            // In case there was already a ServiceThrottlingBehavior (this.throttlingBehavior==null),
            // it should have initialized a single ServiceThrottle on all ChannelDispatchers.  As
            // we loop through the ChannelDispatchers, we verify that and modify the ServiceThrottle
            // to guard MaxPoolSize.
            ServiceThrottle throttle = null;

            foreach (ChannelDispatcherBase cdb in serviceHostBase.ChannelDispatchers)
            {
                ChannelDispatcher cd = cdb as ChannelDispatcher;
                if (cd != null)
                {
                    // Make sure there is exactly one throttle used by all endpoints.
                    // If there were others, we could not enforce MaxPoolSize.
                    if ((this.throttlingBehavior == null) && (this.maxPoolSize != Int32.MaxValue))
                    {
                        if (throttle == null)
                        {
                            throttle = cd.ServiceThrottle;
                        }
                        if (cd.ServiceThrottle == null)
                        {
                            throw new InvalidOperationException(ResourceHelper.GetString("ExNullThrottle"));
                        }
                        if (throttle != cd.ServiceThrottle)
                        {
                            throw new InvalidOperationException(ResourceHelper.GetString("ExDifferentThrottle"));
                        }
                    }

                    foreach (EndpointDispatcher ed in cd.Endpoints)
                    {
                        // Assign it to DispatchBehavior in each endpoint.
                        ed.DispatchRuntime.InstanceProvider = instanceProvider;
                    }
                }
            }

            // Set the MaxConcurrentInstances to limit the number of items that will
            // ever be requested from the pool.
            if ((throttle != null) && (throttle.MaxConcurrentInstances > this.maxPoolSize))
            {
                throttle.MaxConcurrentInstances = this.maxPoolSize;
            }
        }
コード例 #8
0
 private void ConfigureChannelDispatcher(
     ServiceDescription serviceDescription, ChannelDispatcher dispatcher)
 {
     dispatcher.Endpoints.ForEach(endpoint =>
     {
         endpoint.DispatchRuntime.InstanceProvider =
             new UnityInstanceProvider(_container, serviceDescription.ServiceType);
         endpoint.DispatchRuntime.ConcurrencyMode = ConcurrencyMode.Multiple;
     });
 }
コード例 #9
0
        public void ApplyDispatchBehavior(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase)
        {
            IErrorHandler errorHandler = new ServiceErrorHandler();

            foreach (ChannelDispatcherBase channelDispatcherBase in serviceHostBase.ChannelDispatchers)
            {
                ChannelDispatcher channelDispatcher = channelDispatcherBase as ChannelDispatcher;
                channelDispatcher.ErrorHandlers.Add(errorHandler);
            }
        }
        /// <summary>
        /// Applies the dispatch behavior.
        /// </summary>
        /// <param name="description">The description.</param>
        /// <param name="serviceHostBase">The service host base.</param>
        public void ApplyDispatchBehavior(ServiceDescription description, ServiceHostBase serviceHostBase)
        {
            IErrorHandler errorHandler = (IErrorHandler)Activator.CreateInstance(_errorHandlerType);

            foreach (ChannelDispatcherBase channelDispatcherBase in serviceHostBase.ChannelDispatchers)
            {
                ChannelDispatcher channelDispatcher = (ChannelDispatcher)channelDispatcherBase;
                channelDispatcher.ErrorHandlers.Add(errorHandler);
            }
        }
コード例 #11
0
        public void ApplyDispatchBehavior(ServiceDescription description, ServiceHostBase serviceHostBase)
        {
            var errorHandler = (IErrorHandler)Activator.CreateInstance(typeof(GlobalErrorHandler));

            foreach (ChannelDispatcherBase channelDispatcherBase in serviceHostBase.ChannelDispatchers)
            {
                ChannelDispatcher channelDispatcher = channelDispatcherBase as ChannelDispatcher;
                channelDispatcher.ErrorHandlers.Add(errorHandler);
            }
        }
コード例 #12
0
        public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
        {
            IErrorHandler errorHandler = new LogErrorHandler();

            foreach (var cdb in serviceHostBase.ChannelDispatchers)
            {
                ChannelDispatcher cd = cdb as ChannelDispatcher;
                cd?.ErrorHandlers.Add(errorHandler);
            }
        }
コード例 #13
0
 private void AddErrorHandler(ChannelDispatcher channelDispatcher)
 {
     if (!channelDispatcher.IncludeExceptionDetailInFaults &&
         !ContainsExceptionShieldingErrorHandler(channelDispatcher.ErrorHandlers) &&
         !ContainsMetadataEndpoint(channelDispatcher.Endpoints))
     {
         IErrorHandler errorHandler = new ExceptionShieldingErrorHandler(exceptionPolicyName);
         channelDispatcher.ErrorHandlers.Add(errorHandler);
     }
 }
コード例 #14
0
        public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
        {
            RequestCallRateInspector interceptor        = new RequestCallRateInspector();
            ChannelDispatcher        endpointDispatcher = serviceHostBase.ChannelDispatchers[0] as ChannelDispatcher;

            if (endpointDispatcher != null)
            {
                endpointDispatcher.Endpoints[0].DispatchRuntime.MessageInspectors.Add(interceptor);
            }
        }
コード例 #15
0
        /// <summary>
        /// Registering the instance of global error handler in
        /// dispatch behavior of the service
        /// </summary>
        /// <param name="description">description</param>
        /// <param name="serviceHostBase">serviceHostBase</param>
        void IServiceBehavior.ApplyDispatchBehavior(ServiceDescription description, ServiceHostBase serviceHostBase)
        {
            IErrorHandler errorHandler = (IErrorHandler)AutofacHostFactory.Container.Resolve(errorHandlerType);

            foreach (ChannelDispatcherBase channelDispatcherBase in serviceHostBase.ChannelDispatchers)
            {
                ChannelDispatcher channelDispatcher = channelDispatcherBase as ChannelDispatcher;
                channelDispatcher.ErrorHandlers.Add(errorHandler);
            }
        }
コード例 #16
0
        public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
        {
            IErrorHandler errorHandler = new ErrorHandler(this.HandlerMethod);

            foreach (ChannelDispatcherBase channelDispatcherBase in serviceHostBase.ChannelDispatchers)
            {
                ChannelDispatcher channelDispatcher = channelDispatcherBase as ChannelDispatcher;
                channelDispatcher.ErrorHandlers.Add(errorHandler);
            }
        }
        public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
        {
            for (var i = serviceHostBase.ChannelDispatchers.Count - 1; i >= 0; i--)
            {
                var dispatcher = serviceHostBase.ChannelDispatchers[i] as ChannelDispatcher;
                if (dispatcher == null)
                {
                    continue;
                }

                if (!UsesDefaultHttpListener(dispatcher))
                {
                    continue;
                }

                var url     = dispatcher.Listener.Uri;
                var binding = null as Binding;
                if (url.Scheme == "http")
                {
                    binding = new BasicHttpBinding();
                }
                else if (url.Scheme == "https")
                {
                    binding = new BasicHttpsBinding();
                }

                serviceHostBase.ChannelDispatchers.RemoveAt(i);

                if (binding == null)
                {
                    continue;
                }

                binding.Name = $"AspNetCore{dispatcher.BindingName}";
                var custom   = _sanitizer.SanitizeBinding(binding) as CustomBinding;
                var encoding = custom.Elements.OfType <MessageEncodingBindingElement>().First();
                encoding.MessageVersion = MessageVersion.None;
                var transport  = custom.Elements.OfType <TransportBindingElement>().First();
                var parameters = _bindingParameters.GetOrAdd(url, key => new BindingParameterCollection());

                var context  = new BindingContext(custom, parameters, url, string.Empty, ListenUriMode.Explicit);
                var listener = transport.BuildChannelListener <IReplyChannel>(context) as AspNetCoreChannelListener;
                listener.IsGet = true;

                var replacement = new ChannelDispatcher(listener, custom.Name, custom);

                foreach (var endpoint in dispatcher.Endpoints)
                {
                    replacement.Endpoints.Add(Copy(endpoint));
                }

                replacement.MessageVersion = encoding.MessageVersion;
                serviceHostBase.ChannelDispatchers.Add(replacement);
            }
        }
コード例 #18
0
        public void InitializeRuntime3()
        {
            var port = NetworkHelpers.FindFreePort();

            using (ServiceHost host = new ServiceHost(typeof(MyService), new Uri("http://localhost:" + port))) {
                host.AddServiceEndpoint(typeof(IMyContract), new BasicHttpBinding(), "");
                host.Description.Behaviors.Add(new ServiceMetadataBehavior()
                {
                    HttpGetEnabled = true, HttpGetUrl = new Uri("http://localhost:" + port + "/mex")
                });
                host.Description.Behaviors.Find <ServiceDebugBehavior> ().HttpHelpPageUrl = new Uri("http://localhost:" + port + "/help");

                Assert.AreEqual(0, host.ChannelDispatchers.Count, "ChannelDispatchers.Count #1");

                host.Open();

                Assert.AreEqual(3, host.ChannelDispatchers.Count, "ChannelDispatchers.Count #2");

                ChannelDispatcher cd = (ChannelDispatcher)host.ChannelDispatchers [1];
                Assert.AreEqual(1, cd.Endpoints.Count, "Endpoints.Count");

                EndpointDispatcher ed = cd.Endpoints [0];
                Assert.AreEqual(typeof(EndpointAddressMessageFilter), ed.AddressFilter.GetType(), "AddressFilter #1");
                Assert.AreEqual(cd, ed.ChannelDispatcher, "ChannelDispatcher #1");
                Assert.AreEqual(typeof(MatchAllMessageFilter), ed.ContractFilter.GetType(), "ContractFilter #1");
                Assert.AreEqual("IHttpGetHelpPageAndMetadataContract", ed.ContractName, "ContractName #1");
                Assert.AreEqual("http://schemas.microsoft.com/2006/04/http/metadata", ed.ContractNamespace, "ContractNamespace #1");
                Assert.AreEqual(0, ed.FilterPriority, "FilterPriority #1");

                EndpointAddress ea = ed.EndpointAddress;
                // TODO

                DispatchRuntime dr = ed.DispatchRuntime;
                // TODO

                cd = (ChannelDispatcher)host.ChannelDispatchers [2];
                Assert.AreEqual(1, cd.Endpoints.Count, "Endpoints.Count");

                ed = cd.Endpoints [0];
                Assert.AreEqual(typeof(EndpointAddressMessageFilter), ed.AddressFilter.GetType(), "AddressFilter #2");
                Assert.AreEqual(cd, ed.ChannelDispatcher, "ChannelDispatcher #2");
                Assert.AreEqual(typeof(MatchAllMessageFilter), ed.ContractFilter.GetType(), "ContractFilter #2");
                Assert.AreEqual("IHttpGetHelpPageAndMetadataContract", ed.ContractName, "ContractName #2");
                Assert.AreEqual("http://schemas.microsoft.com/2006/04/http/metadata", ed.ContractNamespace, "ContractNamespace #2");
                Assert.AreEqual(0, ed.FilterPriority, "FilterPriority #2");

                ea = ed.EndpointAddress;
                // TODO

                dr = ed.DispatchRuntime;
                // TODO

                host.Close();
            }
        }
コード例 #19
0
 public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
 {
     foreach (ChannelDispatcherBase channelDispatcherBase in serviceHostBase.ChannelDispatchers)
     {
         ChannelDispatcher channelDispatcher = channelDispatcherBase as ChannelDispatcher;
         if (channelDispatcher != null)
         {
             channelDispatcher.ErrorHandlers.Add(this);
         }
     }
 }
コード例 #20
0
 //改变服务端行为
 private void ApplyDispatchBehavior(ChannelDispatcher dispatcher)
 {
     foreach (IErrorHandler errorHandler in dispatcher.ErrorHandlers)
     {
         if (errorHandler is FaultsHandler)
         {
             return;
         }
     }
     dispatcher.ErrorHandlers.Add(new FaultsHandler());
 }
コード例 #21
0
 public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
 {
     foreach (ChannelDispatcherBase channelDispatcherBase in serviceHostBase.ChannelDispatchers)
     {
         ChannelDispatcher channelDispatcher = (ChannelDispatcher)channelDispatcherBase;
         foreach (EndpointDispatcher endpointDispatcher in channelDispatcher.Endpoints)
         {
             endpointDispatcher.ChannelDispatcher.ErrorHandlers.Add(this);
         }
     }
 }
コード例 #22
0
        public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
        {
            IErrorHandler errorHandler;

            errorHandler = (IErrorHandler)Activator.CreateInstance(errorHandlerType);
            foreach (ChannelDispatcherBase cdb in serviceHostBase.ChannelDispatchers)
            {
                ChannelDispatcher cd = cdb as ChannelDispatcher;
                cd.ErrorHandlers.Add(errorHandler);
            }
        }
コード例 #23
0
 public virtual void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
 {
     if (Activator.CreateInstance(_errorHandlerType) is IErrorHandler errorHandler)
     {
         foreach (ChannelDispatcherBase dispatcher in serviceHostBase.ChannelDispatchers)
         {
             ChannelDispatcher cd = dispatcher as ChannelDispatcher;
             cd.ErrorHandlers.Add(errorHandler);
         }
     }
 }
コード例 #24
0
        private static ChannelDispatcher CreateChannelDispatchers()
        {
            var channelListener   = new Mock <IChannelListener>();
            var channelDispatcher = new ChannelDispatcher(channelListener.Object);

            channelDispatcher.Endpoints.Add(new EndpointDispatcher(new EndpointAddress("http://foo"), nameof(Int32), "ns"));
            channelDispatcher.Endpoints.Add(new EndpointDispatcher(new EndpointAddress("http://foo"), nameof(String), "ns"));
            channelDispatcher.Endpoints.Add(new EndpointDispatcher(new EndpointAddress("http://foo"), nameof(Int64), "ns"));

            return(channelDispatcher);
        }
コード例 #25
0
        public void CreateNewChannelDispatcherWithDefaultHandler()
        {
            var dispatcher        = new ChannelDispatcher();
            var defaultDispatcher = new CounterHandler();

            dispatcher.RegisterDefault(defaultDispatcher);
            Assert.IsNotNull(dispatcher.DefaultHandler);

            dispatcher.Handle("/services/test", "data...");
            Assert.AreEqual(1, defaultDispatcher.Calls, "Invalid number of notifications!");
        }
コード例 #26
0
 void IEndpointBehavior.ApplyClientBehavior(ServiceEndpoint serviceEndpoint, ClientRuntime behavior)
 {
     if (this.transactionTimeout != TimeSpan.Zero)
     {
         ChannelDispatcher channelDispatcher = behavior.CallbackDispatchRuntime.ChannelDispatcher;
         if (((channelDispatcher != null) && (channelDispatcher.TransactionTimeout == TimeSpan.Zero)) || (channelDispatcher.TransactionTimeout > this.transactionTimeout))
         {
             channelDispatcher.TransactionTimeout = this.transactionTimeout;
         }
     }
 }
コード例 #27
0
        private static void OutputThrottlingConfiguration(ServiceHost host)
        {
            // This is output just for demonstration purposes
            // Configure in config file
            ChannelDispatcher dispatcher = host.ChannelDispatchers[0] as ChannelDispatcher;

            if (dispatcher != null)
            {
                Console.WriteLine("The following throttling configuration is in use (this can be configured in the config file for the service) :-");
            }
        }
コード例 #28
0
        private static void OutputThrottlingConfiguration(ServiceHost host)
        {
            // This is output just for demonstration purposes
            // Try reducing the max concurrent calls in config to a low number such as 2, force some long running handling and then observe how service is throttled to the set number of concurrent requests
            ChannelDispatcher dispatcher = host.ChannelDispatchers[0] as ChannelDispatcher;

            if (dispatcher != null)
            {
                Console.WriteLine("The following throttling configuration is in use (this can be configured in the config file for the service) :-");
            }
        }
コード例 #29
0
		// Token: 0x06000C5A RID: 3162 RVA: 0x0002E180 File Offset: 0x0002C380
		public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
		{
			foreach (ChannelDispatcherBase channelDispatcherBase in serviceHostBase.ChannelDispatchers)
			{
				ChannelDispatcher channelDispatcher = (ChannelDispatcher)channelDispatcherBase;
				foreach (EndpointDispatcher endpointDispatcher in channelDispatcher.Endpoints)
				{
					endpointDispatcher.DispatchRuntime.MessageInspectors.Add(new OWAMessageInspector());
				}
			}
		}
コード例 #30
0
    public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
    {
        ChannelDispatcher channelDispatcher = endpointDispatcher.ChannelDispatcher;

        if (channelDispatcher != null)
        {
            foreach (EndpointDispatcher ed in channelDispatcher.Endpoints)
            {
                ed.DispatchRuntime.MessageInspectors.Add(new MyMessageInspector());
            }
        }
    }
コード例 #31
0
ファイル: ServiceThrottle.cs プロジェクト: nickchal/pash
		internal ServiceThrottle (ChannelDispatcher owner)
		{
			if (owner == null)
				throw new ArgumentNullException ("owner");
			this.owner = owner;
		}