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); }
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. } }
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); }
protected void UnregisterListenerCommon(ChannelDispatcher channel, TimeSpan timeout) { lock (entries_lock) { var entry = Entries.First(e => e.ChannelDispatcher == channel); Entries.Remove(entry); entry.WaitHandle.Set(); } }
void IEndpointBehavior.ApplyClientBehavior(ServiceEndpoint serviceEndpoint, ClientRuntime behavior) { ChannelDispatcher channelDispatcher = behavior.CallbackDispatchRuntime.ChannelDispatcher; if (channelDispatcher != null && this.includeExceptionDetailInFaults) { channelDispatcher.IncludeExceptionDetailInFaults = true; } }
void SetIsolationLevel(ChannelDispatcher channelDispatcher) { if (channelDispatcher == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("channelDispatcher"); } channelDispatcher.TransactionIsolationLevel = this.transactionIsolationLevel; }
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; } }
private void ConfigureChannelDispatcher( ServiceDescription serviceDescription, ChannelDispatcher dispatcher) { dispatcher.Endpoints.ForEach(endpoint => { endpoint.DispatchRuntime.InstanceProvider = new UnityInstanceProvider(_container, serviceDescription.ServiceType); endpoint.DispatchRuntime.ConcurrencyMode = ConcurrencyMode.Multiple; }); }
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); } }
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); } }
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); } }
private void AddErrorHandler(ChannelDispatcher channelDispatcher) { if (!channelDispatcher.IncludeExceptionDetailInFaults && !ContainsExceptionShieldingErrorHandler(channelDispatcher.ErrorHandlers) && !ContainsMetadataEndpoint(channelDispatcher.Endpoints)) { IErrorHandler errorHandler = new ExceptionShieldingErrorHandler(exceptionPolicyName); channelDispatcher.ErrorHandlers.Add(errorHandler); } }
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); } }
/// <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); } }
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); } }
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(); } }
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); } } }
//改变服务端行为 private void ApplyDispatchBehavior(ChannelDispatcher dispatcher) { foreach (IErrorHandler errorHandler in dispatcher.ErrorHandlers) { if (errorHandler is FaultsHandler) { return; } } dispatcher.ErrorHandlers.Add(new FaultsHandler()); }
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); } } }
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); } }
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); } } }
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); }
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!"); }
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; } } }
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) :-"); } }
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) :-"); } }
// 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()); } } }
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()); } } }
internal ServiceThrottle (ChannelDispatcher owner) { if (owner == null) throw new ArgumentNullException ("owner"); this.owner = owner; }