static InProcFactory() { NetNamedPipeBinding binding; try { binding = new NetNamedPipeContextBinding("InProcFactory"); } catch { binding = new NetNamedPipeContextBinding(); } binding.TransactionFlow = true; Binding = binding; binding.MaxReceivedMessageSize *= 4; AppDomain.CurrentDomain.ProcessExit += delegate { foreach (Dictionary <Type, Tuple <ServiceHost, EndpointAddress> > endpoints in m_Hosts.Values) { foreach (Tuple <ServiceHost, EndpointAddress> record in endpoints.Values) { record.Item1.Close(); } } }; }
static InProcFactory() { NetNamedPipeBinding binding; try { binding = new NetNamedPipeContextBinding("InProcFactory"); } catch { binding = new NetNamedPipeContextBinding(); } binding.TransactionFlow = true; Binding = binding; AppDomain.CurrentDomain.ProcessExit += delegate { foreach (HostRecord hostRecord in m_Hosts.Values) { hostRecord.Host.Close(); } }; }
static InProcFactory() { NetNamedPipeBinding binding; try { binding = new NetNamedPipeContextBinding("InProcFactory"); } catch { binding = new NetNamedPipeContextBinding(); } binding.TransactionFlow = true; Binding = binding; binding.MaxReceivedMessageSize *= 4; EventHandler closeAllHosts = delegate { foreach (Dictionary <Type, Tuple <ServiceHost, EndpointAddress> > endpoints in m_Hosts.Values) { foreach (Tuple <ServiceHost, EndpointAddress> record in endpoints.Values) { if (record.Item1.State == CommunicationState.Opened) { record.Item1.Close(); } } } }; AppDomain.CurrentDomain.DomainUnload += closeAllHosts; AppDomain.CurrentDomain.ProcessExit += closeAllHosts; }
protected override void OnApplyConfiguration(Binding binding) { base.OnApplyConfiguration(binding); NetNamedPipeContextBinding netNamedPipeContextBinding = binding as NetNamedPipeContextBinding; Debug.Assert(netNamedPipeContextBinding != null); netNamedPipeContextBinding.ContextProtectionLevel = ContextProtectionLevel; }
static EndpointAddress GetAddress <S, I>(IServiceBehavior serviceBehavior, NetNamedPipeContextBinding binding) where I : class where S : class, I { if (m_Hosts.ContainsKey(typeof(S))) { Debug.Assert(m_Hosts[typeof(S)].ContainsKey(typeof(I))); return(m_Hosts[typeof(S)][typeof(I)].Item2); } else { ServiceHost <S> host; if (m_Singletons.ContainsKey(typeof(S))) { S singleton = m_Singletons[typeof(S)] as S; Debug.Assert(singleton != null); host = new ServiceHost <S>(singleton); } else { host = new ServiceHost <S>(); } if (serviceBehavior != null) { host.Description.Behaviors.Insert(0, serviceBehavior); } Type[] contracts = GetContracts <S>(); Debug.Assert(contracts.Any()); m_Hosts[typeof(S)] = new Dictionary <Type, Tuple <ServiceHost, EndpointAddress> >(); foreach (Type contract in contracts) { string address = BaseAddress + Guid.NewGuid() + "_" + contract; m_Hosts[typeof(S)][contract] = new Tuple <ServiceHost, EndpointAddress>(host, new EndpointAddress(address)); host.AddServiceEndpoint(contract, binding, address); } if (m_Throttles.ContainsKey(typeof(S))) { host.SetThrottle(m_Throttles[typeof(S)]); } if (Scope == null) { throw new InvalidOperationException(string.Format("Scope is not set yet when trying to instantiate {0}", typeof(I).FullName)); } host.AddDependencyInjectionBehavior <S>(Scope); host.IncludeExceptionDetailInFaults = true; host.AddGenericResolver(defaultGenericResolverTypes); defaultServiceBehaviors.ForEach(b => host.Description.Behaviors.Add(b)); host.Open(); } return(GetAddress <S, I>()); }
internal static I CreateInstance <S, I>(IServiceBehavior serviceBehavior, NetNamedPipeContextBinding proxyBinding, NetNamedPipeContextBinding serviceBinding) where I : class where S : class, I { Debug.Assert(proxyBinding != null); Debug.Assert(serviceBinding != null); EndpointAddress address = GetAddress <S, I>(serviceBehavior, serviceBinding); ChannelFactory <I> factory = new ChannelFactory <I>(proxyBinding, address); factory.AddGenericResolver(); return(factory.CreateChannel()); }
static EndpointAddress GetAddress <S, I>(IServiceBehavior serviceBehavior, NetNamedPipeContextBinding binding) where I : class where S : class, I { if (m_Hosts.ContainsKey(typeof(S))) { Debug.Assert(m_Hosts[typeof(S)].ContainsKey(typeof(I))); return(m_Hosts[typeof(S)][typeof(I)].Item2); } else { ServiceHost <S> host; if (m_Singletons.ContainsKey(typeof(S))) { S singleton = m_Singletons[typeof(S)] as S; Debug.Assert(singleton != null); host = new ServiceHost <S>(singleton); } else { host = new ServiceHost <S>(); } if (serviceBehavior != null) { host.Description.Behaviors.Insert(0, serviceBehavior); } Type[] contracts = GetContracts <S>(); Debug.Assert(contracts.Any()); m_Hosts[typeof(S)] = new Dictionary <Type, Tuple <ServiceHost, EndpointAddress> >(); foreach (Type contract in contracts) { string address = BaseAddress + Guid.NewGuid() + "_" + contract; m_Hosts[typeof(S)][contract] = new Tuple <ServiceHost, EndpointAddress>(host, new EndpointAddress(address)); host.AddServiceEndpoint(contract, binding, address); } if (m_Throttles.ContainsKey(typeof(S))) { host.SetThrottle(m_Throttles[typeof(S)]); } host.Open(); } return(GetAddress <S, I>()); }
internal static ChannelFactory <I> InitializeInstance <S, I>(IServiceBehavior serviceBehavior, IEndpointBehavior clientBehavior, NetNamedPipeContextBinding proxyBinding, NetNamedPipeContextBinding serviceBinding) where I : class where S : class, I { if (serviceBinding == null) { serviceBinding = Binding as NetNamedPipeContextBinding; } EndpointAddress address = GetAddress <S, I>(serviceBehavior, serviceBinding); ChannelFactory <I> factory = new ChannelFactory <I>(proxyBinding, address); factory.AddGenericResolver(defaultGenericResolverTypes); factory.Endpoint.EndpointBehaviors.Add(clientBehavior); return(factory); }
static InProcFactory() { NetNamedPipeBinding binding; try { binding = new NetNamedPipeContextBinding("InProcFactory"); } catch { binding = new NetNamedPipeContextBinding(); } binding.TransactionFlow = true; Binding = binding; binding.MaxReceivedMessageSize *= 4; AppDomain.CurrentDomain.DomainUnload += CloseAllHosts; AppDomain.CurrentDomain.ProcessExit += CloseAllHosts; }