using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceProcess;
using GeometryServiceLibrary;

namespace GeometryServiceHost.WindowsService
{
    public partial class GeometryWindowsService : ServiceBase
    {
        private ServiceHost host;

        public GeometryWindowsService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            CloseHost();

            host = new ServiceHost(typeof(GeometryService));
            //Add endpoint
            host.AddServiceEndpoint(typeof(IGeometryService), 
                new WSHttpBinding(), 
                new System.Uri("http://localhost:8733/Design_Time_Addresses/GeometryServiceLibrary/GeometryService/"));
            
            host.Open();
        }

        protected override void OnStop()
        {
            CloseHost();
        }

        private void CloseHost()
        {
            if (host != null)
            {
                host.Close();
                host = null;
            }
        }
    }
}
