protected override void InitializeRuntime() { ComPlusServiceHostTrace.Trace(TraceEventType.Information, TraceCode.ComIntegrationServiceHostStartingService, SR.TraceCodeComIntegrationServiceHostStartingService, this.info); try { DispatcherBuilder dispatcherBuilder = new DispatcherBuilder(); dispatcherBuilder.InitializeServiceHost(this.Description, this); } catch (Exception e) { if (System.ServiceModel.DiagnosticUtility.ShouldTraceError) { DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, (ushort)System.Runtime.Diagnostics.EventLogCategory.ComPlus, (uint)System.Runtime.Diagnostics.EventLogEventId.ComPlusServiceHostStartingServiceError, this.info.AppID.ToString(), this.info.Clsid.ToString(), e.ToString()); } throw; } ComPlusServiceHostTrace.Trace(TraceEventType.Verbose, TraceCode.ComIntegrationServiceHostStartedServiceDetails, SR.TraceCodeComIntegrationServiceHostStartedServiceDetails, this.info, this.Description); ComPlusServiceHostTrace.Trace(TraceEventType.Information, TraceCode.ComIntegrationServiceHostStartedService, SR.TraceCodeComIntegrationServiceHostStartedService, this.info); }
public List <IServiceDispatcher> GetDispatchers() { if (_dispatchers == null) { _dispatchers = DispatcherBuilder.BuildDispatcher <TService>(this, _services); } return(_dispatchers); }
protected override void InitializeRuntime() { MessageFilter contractFilter = this.listenerFilter; int filterPriority = 10; Type[] endpointChannelTypes = new Type[] { typeof(IReplyChannel), typeof(IDuplexChannel), typeof(IReplySessionChannel), typeof(IDuplexSessionChannel) }; IChannelListener listener = null; BindingParameterCollection parameters = new BindingParameterCollection(this.channelBuilder.BindingParameters); Binding binding = this.channelBuilder.Binding; binding.ReceiveTimeout = this.authenticator.NegotiationTimeout; parameters.Add(new ChannelDemuxerFilter(contractFilter, filterPriority)); DispatcherBuilder.MaybeCreateListener(true, endpointChannelTypes, binding, parameters, this.listenUri, "", ListenUriMode.Explicit, this.ServiceThrottle, out listener); if (listener == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.CannotCreateTwoWayListenerForNegotiation))); } ChannelDispatcher channelDispatcher = new ChannelDispatcher(listener, null, binding); channelDispatcher.MessageVersion = binding.MessageVersion; channelDispatcher.ManualAddressing = true; channelDispatcher.ServiceThrottle = new ServiceThrottle(this); channelDispatcher.ServiceThrottle.MaxConcurrentCalls = this.authenticator.MaximumConcurrentNegotiations; channelDispatcher.ServiceThrottle.MaxConcurrentSessions = this.authenticator.MaximumConcurrentNegotiations; EndpointDispatcher endpointDispatcher = new EndpointDispatcher(new EndpointAddress(this.listenUri), "SecurityNegotiationContract", NamingHelper.DefaultNamespace, true); endpointDispatcher.DispatchRuntime.SingletonInstanceContext = new InstanceContext(null, this.authenticator, false); endpointDispatcher.DispatchRuntime.ConcurrencyMode = ConcurrencyMode.Multiple; endpointDispatcher.AddressFilter = new MatchAllMessageFilter(); endpointDispatcher.ContractFilter = contractFilter; endpointDispatcher.FilterPriority = filterPriority; endpointDispatcher.DispatchRuntime.PrincipalPermissionMode = PrincipalPermissionMode.None; endpointDispatcher.DispatchRuntime.InstanceContextProvider = new SingletonInstanceContextProvider(endpointDispatcher.DispatchRuntime); endpointDispatcher.DispatchRuntime.SynchronizationContext = null; DispatchOperation operation = new DispatchOperation(endpointDispatcher.DispatchRuntime, "*", MessageHeaders.WildcardAction, MessageHeaders.WildcardAction); operation.Formatter = new MessageOperationFormatter(); operation.Invoker = new NegotiationSyncInvoker(this.authenticator); endpointDispatcher.DispatchRuntime.UnhandledDispatchOperation = operation; channelDispatcher.Endpoints.Add(endpointDispatcher); this.ChannelDispatchers.Add(channelDispatcher); }
protected override void InitializeRuntime() { MessageFilter listenerFilter = this.listenerFilter; int priority = 10; System.Type[] supportedChannels = new System.Type[] { typeof(IReplyChannel), typeof(IDuplexChannel), typeof(IReplySessionChannel), typeof(IDuplexSessionChannel) }; IChannelListener result = null; BindingParameterCollection parameters = new BindingParameterCollection(this.channelBuilder.BindingParameters); Binding binding = this.channelBuilder.Binding; binding.ReceiveTimeout = this.authenticator.NegotiationTimeout; parameters.Add(new ChannelDemuxerFilter(listenerFilter, priority)); DispatcherBuilder.MaybeCreateListener(true, supportedChannels, binding, parameters, this.listenUri, "", ListenUriMode.Explicit, base.ServiceThrottle, out result); if (result == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("CannotCreateTwoWayListenerForNegotiation"))); } ChannelDispatcher item = new ChannelDispatcher(result, null, binding) { MessageVersion = binding.MessageVersion, ManualAddressing = true, ServiceThrottle = new ServiceThrottle(this) }; item.ServiceThrottle.MaxConcurrentCalls = this.authenticator.MaximumConcurrentNegotiations; item.ServiceThrottle.MaxConcurrentSessions = this.authenticator.MaximumConcurrentNegotiations; EndpointDispatcher dispatcher2 = new EndpointDispatcher(new EndpointAddress(this.listenUri, new AddressHeader[0]), "SecurityNegotiationContract", "http://tempuri.org/", true) { DispatchRuntime = { SingletonInstanceContext = new InstanceContext(null, this.authenticator, false), ConcurrencyMode = ConcurrencyMode.Multiple }, AddressFilter = new MatchAllMessageFilter(), ContractFilter = listenerFilter, FilterPriority = priority }; dispatcher2.DispatchRuntime.PrincipalPermissionMode = PrincipalPermissionMode.None; dispatcher2.DispatchRuntime.InstanceContextProvider = new SingletonInstanceContextProvider(dispatcher2.DispatchRuntime); dispatcher2.DispatchRuntime.SynchronizationContext = null; DispatchOperation operation = new DispatchOperation(dispatcher2.DispatchRuntime, "*", "*", "*") { Formatter = new MessageOperationFormatter(), Invoker = new NegotiationSyncInvoker <T>(this.authenticator) }; dispatcher2.DispatchRuntime.UnhandledDispatchOperation = operation; item.Endpoints.Add(dispatcher2); base.ChannelDispatchers.Add(item); }
private void ServerComunication(Action <IConfigureDispatcher> cfg) { _dispBuilder = new DispatcherBuilder(); cfg(_dispBuilder); }
public static ServiceChannelFactory BuildChannelFactory(ServiceEndpoint serviceEndpoint, bool useActiveAutoClose) { if (serviceEndpoint == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serviceEndpoint"); } serviceEndpoint.EnsureInvariants(); serviceEndpoint.ValidateForClient(); ChannelRequirements requirements; ContractDescription contractDescription = serviceEndpoint.Contract; ChannelRequirements.ComputeContractRequirements(contractDescription, out requirements); BindingParameterCollection parameters; ClientRuntime clientRuntime = DispatcherBuilder.BuildProxyBehavior(serviceEndpoint, out parameters); Binding binding = serviceEndpoint.Binding; Type[] requiredChannels = ChannelRequirements.ComputeRequiredChannels(ref requirements); CustomBinding customBinding = new CustomBinding(binding); BindingContext context = new BindingContext(customBinding, parameters); InternalDuplexBindingElement internalDuplexBindingElement = null; InternalDuplexBindingElement.AddDuplexFactorySupport(context, ref internalDuplexBindingElement); customBinding = new CustomBinding(context.RemainingBindingElements); customBinding.CopyTimeouts(serviceEndpoint.Binding); foreach (Type type in requiredChannels) { if (type == typeof(IOutputChannel) && customBinding.CanBuildChannelFactory <IOutputChannel>(parameters)) { return(new ServiceChannelFactoryOverOutput(customBinding.BuildChannelFactory <IOutputChannel>(parameters), clientRuntime, binding)); } if (type == typeof(IRequestChannel) && customBinding.CanBuildChannelFactory <IRequestChannel>(parameters)) { return(new ServiceChannelFactoryOverRequest(customBinding.BuildChannelFactory <IRequestChannel>(parameters), clientRuntime, binding)); } if (type == typeof(IDuplexChannel) && customBinding.CanBuildChannelFactory <IDuplexChannel>(parameters)) { if (requirements.usesReply && binding.CreateBindingElements().Find <TransportBindingElement>().ManualAddressing) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException( SR.GetString(SR.CantCreateChannelWithManualAddressing))); } return(new ServiceChannelFactoryOverDuplex(customBinding.BuildChannelFactory <IDuplexChannel>(parameters), clientRuntime, binding)); } if (type == typeof(IOutputSessionChannel) && customBinding.CanBuildChannelFactory <IOutputSessionChannel>(parameters)) { return(new ServiceChannelFactoryOverOutputSession(customBinding.BuildChannelFactory <IOutputSessionChannel>(parameters), clientRuntime, binding, false)); } if (type == typeof(IRequestSessionChannel) && customBinding.CanBuildChannelFactory <IRequestSessionChannel>(parameters)) { return(new ServiceChannelFactoryOverRequestSession(customBinding.BuildChannelFactory <IRequestSessionChannel>(parameters), clientRuntime, binding, false)); } if (type == typeof(IDuplexSessionChannel) && customBinding.CanBuildChannelFactory <IDuplexSessionChannel>(parameters)) { if (requirements.usesReply && binding.CreateBindingElements().Find <TransportBindingElement>().ManualAddressing) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException( SR.GetString(SR.CantCreateChannelWithManualAddressing))); } return(new ServiceChannelFactoryOverDuplexSession(customBinding.BuildChannelFactory <IDuplexSessionChannel>(parameters), clientRuntime, binding, useActiveAutoClose)); } } foreach (Type type in requiredChannels) { // For SessionMode.Allowed or SessionMode.NotAllowed we will accept session-ful variants as well if (type == typeof(IOutputChannel) && customBinding.CanBuildChannelFactory <IOutputSessionChannel>(parameters)) { return(new ServiceChannelFactoryOverOutputSession(customBinding.BuildChannelFactory <IOutputSessionChannel>(parameters), clientRuntime, binding, true)); } if (type == typeof(IRequestChannel) && customBinding.CanBuildChannelFactory <IRequestSessionChannel>(parameters)) { return(new ServiceChannelFactoryOverRequestSession(customBinding.BuildChannelFactory <IRequestSessionChannel>(parameters), clientRuntime, binding, true)); } // and for SessionMode.Required, it is possible that the InstanceContextProvider is handling the session management, so // accept datagram variants if that is the case if (type == typeof(IRequestSessionChannel) && customBinding.CanBuildChannelFactory <IRequestChannel>(parameters) && customBinding.GetProperty <IContextSessionProvider>(parameters) != null) { return(new ServiceChannelFactoryOverRequest(customBinding.BuildChannelFactory <IRequestChannel>(parameters), clientRuntime, binding)); } } // we put a lot of work into creating a good error message, as this is a common case Dictionary <Type, byte> supportedChannels = new Dictionary <Type, byte>(); if (customBinding.CanBuildChannelFactory <IOutputChannel>(parameters)) { supportedChannels.Add(typeof(IOutputChannel), 0); } if (customBinding.CanBuildChannelFactory <IRequestChannel>(parameters)) { supportedChannels.Add(typeof(IRequestChannel), 0); } if (customBinding.CanBuildChannelFactory <IDuplexChannel>(parameters)) { supportedChannels.Add(typeof(IDuplexChannel), 0); } if (customBinding.CanBuildChannelFactory <IOutputSessionChannel>(parameters)) { supportedChannels.Add(typeof(IOutputSessionChannel), 0); } if (customBinding.CanBuildChannelFactory <IRequestSessionChannel>(parameters)) { supportedChannels.Add(typeof(IRequestSessionChannel), 0); } if (customBinding.CanBuildChannelFactory <IDuplexSessionChannel>(parameters)) { supportedChannels.Add(typeof(IDuplexSessionChannel), 0); } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(ChannelRequirements.CantCreateChannelException( supportedChannels.Keys, requiredChannels, binding.Name)); }
public static ServiceChannelFactory BuildChannelFactory(ServiceEndpoint serviceEndpoint, bool useActiveAutoClose) { ChannelRequirements requirements; BindingParameterCollection parameters; if (serviceEndpoint == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serviceEndpoint"); } serviceEndpoint.EnsureInvariants(); serviceEndpoint.ValidateForClient(); ChannelRequirements.ComputeContractRequirements(serviceEndpoint.Contract, out requirements); System.ServiceModel.Dispatcher.ClientRuntime clientRuntime = DispatcherBuilder.BuildProxyBehavior(serviceEndpoint, out parameters); Binding binding = serviceEndpoint.Binding; System.Type[] requiredChannels = ChannelRequirements.ComputeRequiredChannels(ref requirements); CustomBinding binding2 = new CustomBinding(binding); BindingContext context = new BindingContext(binding2, parameters); InternalDuplexBindingElement internalDuplexBindingElement = null; InternalDuplexBindingElement.AddDuplexFactorySupport(context, ref internalDuplexBindingElement); binding2 = new CustomBinding(context.RemainingBindingElements); binding2.CopyTimeouts(serviceEndpoint.Binding); foreach (System.Type type in requiredChannels) { if ((type == typeof(IOutputChannel)) && binding2.CanBuildChannelFactory <IOutputChannel>(parameters)) { return(new ServiceChannelFactoryOverOutput(binding2.BuildChannelFactory <IOutputChannel>(parameters), clientRuntime, binding)); } if ((type == typeof(IRequestChannel)) && binding2.CanBuildChannelFactory <IRequestChannel>(parameters)) { return(new ServiceChannelFactoryOverRequest(binding2.BuildChannelFactory <IRequestChannel>(parameters), clientRuntime, binding)); } if ((type == typeof(IDuplexChannel)) && binding2.CanBuildChannelFactory <IDuplexChannel>(parameters)) { if (requirements.usesReply && binding.CreateBindingElements().Find <TransportBindingElement>().ManualAddressing) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("CantCreateChannelWithManualAddressing"))); } return(new ServiceChannelFactoryOverDuplex(binding2.BuildChannelFactory <IDuplexChannel>(parameters), clientRuntime, binding)); } if ((type == typeof(IOutputSessionChannel)) && binding2.CanBuildChannelFactory <IOutputSessionChannel>(parameters)) { return(new ServiceChannelFactoryOverOutputSession(binding2.BuildChannelFactory <IOutputSessionChannel>(parameters), clientRuntime, binding, false)); } if ((type == typeof(IRequestSessionChannel)) && binding2.CanBuildChannelFactory <IRequestSessionChannel>(parameters)) { return(new ServiceChannelFactoryOverRequestSession(binding2.BuildChannelFactory <IRequestSessionChannel>(parameters), clientRuntime, binding, false)); } if ((type == typeof(IDuplexSessionChannel)) && binding2.CanBuildChannelFactory <IDuplexSessionChannel>(parameters)) { if (requirements.usesReply && binding.CreateBindingElements().Find <TransportBindingElement>().ManualAddressing) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("CantCreateChannelWithManualAddressing"))); } return(new ServiceChannelFactoryOverDuplexSession(binding2.BuildChannelFactory <IDuplexSessionChannel>(parameters), clientRuntime, binding, useActiveAutoClose)); } } foreach (System.Type type2 in requiredChannels) { if ((type2 == typeof(IOutputChannel)) && binding2.CanBuildChannelFactory <IOutputSessionChannel>(parameters)) { return(new ServiceChannelFactoryOverOutputSession(binding2.BuildChannelFactory <IOutputSessionChannel>(parameters), clientRuntime, binding, true)); } if ((type2 == typeof(IRequestChannel)) && binding2.CanBuildChannelFactory <IRequestSessionChannel>(parameters)) { return(new ServiceChannelFactoryOverRequestSession(binding2.BuildChannelFactory <IRequestSessionChannel>(parameters), clientRuntime, binding, true)); } if (((type2 == typeof(IRequestSessionChannel)) && binding2.CanBuildChannelFactory <IRequestChannel>(parameters)) && (binding2.GetProperty <IContextSessionProvider>(parameters) != null)) { return(new ServiceChannelFactoryOverRequest(binding2.BuildChannelFactory <IRequestChannel>(parameters), clientRuntime, binding)); } } Dictionary <System.Type, byte> dictionary = new Dictionary <System.Type, byte>(); if (binding2.CanBuildChannelFactory <IOutputChannel>(parameters)) { dictionary.Add(typeof(IOutputChannel), 0); } if (binding2.CanBuildChannelFactory <IRequestChannel>(parameters)) { dictionary.Add(typeof(IRequestChannel), 0); } if (binding2.CanBuildChannelFactory <IDuplexChannel>(parameters)) { dictionary.Add(typeof(IDuplexChannel), 0); } if (binding2.CanBuildChannelFactory <IOutputSessionChannel>(parameters)) { dictionary.Add(typeof(IOutputSessionChannel), 0); } if (binding2.CanBuildChannelFactory <IRequestSessionChannel>(parameters)) { dictionary.Add(typeof(IRequestSessionChannel), 0); } if (binding2.CanBuildChannelFactory <IDuplexSessionChannel>(parameters)) { dictionary.Add(typeof(IDuplexSessionChannel), 0); } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(ChannelRequirements.CantCreateChannelException(dictionary.Keys, requiredChannels, binding.Name)); }