示例#1
0
        public void Stop()
        {
            if (host == null)
                return;
            if (host.State == CommunicationState.Opened)
                host.Close();
            host = null;

            #if NET35
            if (discoverer == null)
                return;
            discoverer.Stop();
            discoverer = null;
            #endif
        }
示例#2
0
        private void CreateServiceHost(IEventService instance)
        {
            var guid = Guid.NewGuid();
            host = new ServiceHost(instance,
                GetUri(guid));
            host.AddServiceEndpoint(
                typeof(IEventService),
                GetBinding(),
                "EventService");
            #if !NET35
            var discoveryBehavior = new ServiceDiscoveryBehavior();
            host.Description.Behaviors.Add(discoveryBehavior);
            host.AddServiceEndpoint(new UdpDiscoveryEndpoint());
            discoveryBehavior.AnnouncementEndpoints.Add(new UdpAnnouncementEndpoint());
            #else
            discoverer = new Discovery.ServiceDiscoverer();
            StartDiscoverer(discoverer, guid);
            #endif

            host.Description.Behaviors.Add(new ServiceThrottlingBehavior
            {
                MaxConcurrentSessions = 1000
            });

            host.Description.Endpoints[0].Contract.Operations[0].Behaviors.Add(new EncryptionBehavior { EncryptionKey = encryptionKey });

            host.Opened += (s, e) => IsStarted = true;
            host.Closed += (s, e) => IsStarted = false;
        }