Beispiel #1
0
        public void OpenHost <TContract, TImplementation>() where TContract : class where TImplementation : TContract
        {
            ServiceHost host = new ServiceHost(typeof(TImplementation));

            host.Opened  += HostStateHandler;
            host.Closed  += HostStateHandler;
            host.Faulted += HostStateHandler;

            host.Open();

            _services.Add(CreateDescription(host), host);
            _serviceImplementations.Add(typeof(TContract).Name, typeof(TImplementation));

            HostStart?.Invoke(typeof(TContract).Name, host);
        }
Beispiel #2
0
        void ICommunicationContract.StartService(ServiceDescriptionDto service)
        {
            if (service != null)
            {
                try
                {
                    ServiceHost           newHost            = null;
                    ServiceDescriptionDto serviceDescription = null;
                    ServiceDescriptionDto oldDescription     = null;

                    for (int i = 0; i < _services.Values.Count; i++)
                    {
                        if (_services.Values.ElementAt(i).Description.Endpoints[0].Contract.Name == service.ServiceType &&
                            _services.Values.ElementAt(i).State == CommunicationState.Closed)
                        {
                            newHost = new ServiceHost(_serviceImplementations[service.ServiceType]);
                            newHost.Open();

                            newHost.Opened  += HostStateHandler;
                            newHost.Closed  += HostStateHandler;
                            newHost.Faulted += HostStateHandler;

                            serviceDescription = CreateDescription(newHost);
                            oldDescription     = _services.Keys.ElementAt(i);

                            break;
                        }
                    }

                    _services.Remove(oldDescription);
                    _services.Add(serviceDescription, newHost);

                    Callback.SendServiceState(serviceDescription);

                    HostStart?.Invoke(serviceDescription.ServiceType, newHost);
                }
                catch (Exception ex)
                {
                }
            }
        }