dattaprasaddhuri Ответов: 0

Ошибка при установке службы windows с помощью команды installutil?


I Will Explain what i am exactly doing.

   (.Net application)
   STEP 1:
       I Have taken the one class library file in which i have added the WCF service. In this service i am peforming operations.

  STEP 2:
      I have added the windows service in the same solution. In this service i have hosted the WCF service and debug it.

      So it is working fine.

 STEP 3:
      Then I had created the set up of that files using installshied(basic msi project) and i install it. It is working fine.

     But I am trying to install it using InstallUtil.exe it is giving error.



сообщение об ошибке:
Installing assembly 'C:\Users\Dattaprasad\Desktop\TestAllBrowswer\WindowsService1.exe'.
Affected parameters are:
   i = 
   logtoconsole = 
   logfile = C:\Users\Dattaprasad\Desktop\TestAllBrowswer\WindowsService1.InstallLog
   assemblypath = C:\Users\Dattaprasad\Desktop\TestAllBrowswer\WindowsService1.exe
   name = HostCompression
Installing service HostCompression...
Service HostCompression has been successfully installed.
Creating EventLog source HostCompression in log Application...
An exception occurred in the OnAfterInstall event handler of System.ServiceProcess.ServiceInstaller.
System.InvalidOperationException: Cannot start service HostCompression on computer '.'.
The inner exception System.ComponentModel.Win32Exception was thrown with the following error message: 
The service did not respond to the start or control request in a timely fashion.
Rolling back assembly 'C:\Users\Dattaprasad\Desktop\TestAllBrowswer\WindowsService1.exe'.
Affected parameters are:
   i = 
   logtoconsole = 
   logfile = C:\Users\Dattaprasad\Desktop\TestAllBrowswer\WindowsService1.InstallLog
   assemblypath = C:\Users\Dattaprasad\Desktop\TestAllBrowswer\WindowsService1.exe
   name = HostCompression
Restoring event log to previous state for source HostCompression.
Service HostCompression is being removed from the system...
Service HostCompression was successfully removed from the system.


Что я уже пробовал:

Файл service1.файл CS :-
ServiceHost m_serviceHost;
        public Service1()
        {
            InitializeComponent();
        }

        public void OnDebug()
        {
            OnStart(null);
        }
        protected override void OnStart(string[] args)
        {
            if (m_serviceHost != null) m_serviceHost.Close();

            //string strAdrHTTP = "http://localhost:9100/CompressService/";
            string strAdrTCP = "net.tcp://localhost:9200/CompressService";
            string strAdrWebHttp = "http://localhost:9100/CompressService";

            Uri[] adrbase = { 
                                //new Uri(strAdrHTTP),
                                new Uri(strAdrTCP), 
                                new Uri(strAdrWebHttp) 
                            };
            m_serviceHost = new ServiceHost(typeof(TestAllBrowser.Test), adrbase);

            // ServiceDebugBehavior debug = m_serviceHost.Description.Behaviors.Find<ServiceDebugBehavior>();


            ServiceMetadataBehavior mBehave = new ServiceMetadataBehavior();
            m_serviceHost.Description.Behaviors.Add(mBehave);

            //m_serviceHost.Description.Behaviors.Add(new ServiceDebugBehavior() { IncludeExceptionDetailInFaults = true });

            #region BasicHttpBinding
            #endregion

            #region NetTcpBinding

            NetTcpBinding tcpb = new NetTcpBinding();
            tcpb.MaxReceivedMessageSize = 2147483647;
            tcpb.MaxBufferPoolSize = 2147483647;
            tcpb.MaxBufferSize = 2147483647;
            tcpb.TransferMode = TransferMode.Streamed;
            //tcpb.ReaderQuotas.MaxArrayLength = 2147483647;
            //tcpb.ReaderQuotas.MaxStringContentLength = 2147483647;
            tcpb.ReceiveTimeout = new TimeSpan(0, 10, 00);
            tcpb.SendTimeout = new TimeSpan(0, 10, 00);
            tcpb.CloseTimeout = new TimeSpan(0, 10, 00);

            m_serviceHost.AddServiceEndpoint(typeof(TestAllBrowser.ITest), tcpb, strAdrTCP);
            m_serviceHost.AddServiceEndpoint(typeof(IMetadataExchange),
            MetadataExchangeBindings.CreateMexTcpBinding(), "mex");

            #endregion

            #region WebHttpBinding

            WebHttpBinding webb = new WebHttpBinding();
            webb.MaxReceivedMessageSize = 2147483647;
            webb.MaxBufferPoolSize = 2147483647;
            webb.MaxBufferSize = 2147483647;
            webb.TransferMode = TransferMode.Streamed;
            //webb.ReaderQuotas.MaxArrayLength = 2147483647;
            //webb.ReaderQuotas.MaxStringContentLength = 2147483647;
            webb.ReceiveTimeout = new TimeSpan(0, 10, 00);
            webb.SendTimeout = new TimeSpan(0, 10, 00);
            webb.CloseTimeout = new TimeSpan(0, 10, 00);
            webb.CrossDomainScriptAccessEnabled = true;

            m_serviceHost.AddServiceEndpoint(typeof(TestAllBrowser.ITest), webb, strAdrWebHttp).Behaviors.Add((IEndpointBehavior)new WebHttpBehavior());

            m_serviceHost.AddServiceEndpoint(typeof(IMetadataExchange),
            MetadataExchangeBindings.CreateMexHttpBinding(), "mex");

            #endregion

            m_serviceHost.Open();

        }

        protected override void OnStop()
        {
            if (m_serviceHost != null)
                m_serviceHost.Close();
            m_serviceHost = null;
        }



Файле projectinstaller.классе по информатике

[RunInstaller(true)]
    public partial class ProjectInstaller : System.Configuration.Install.Installer
    {
        private IContainer components = (IContainer)null;
        private ServiceProcessInstaller process;
        private ServiceInstaller service;
        private ServiceProcessInstaller serviceProcessInstaller1;
        private ServiceInstaller serviceInstaller1;

        public ProjectInstaller()
        {
            this.process = new ServiceProcessInstaller();
            this.process.Account = ServiceAccount.LocalSystem;
            this.service = new ServiceInstaller();
            this.service.ServiceName = "HostCompression";
            this.service.DisplayName = "HostCompression";
            this.service.Description = "WCF Service Hosted";
            this.service.StartType = ServiceStartMode.Automatic;
            this.Installers.Add((Installer)this.process);
            this.Installers.Add((Installer)this.service);
            this.service.AfterInstall += new InstallEventHandler(this.serviceInstaller1_AfterInstall);
        }

        private void serviceInstaller1_AfterInstall(object sender, InstallEventArgs e)
        {
            new ServiceController("HostCompression").Start();
        }

        private void InitializeComponent()
        {
            this.serviceProcessInstaller1 = new System.ServiceProcess.ServiceProcessInstaller();
            this.serviceInstaller1 = new System.ServiceProcess.ServiceInstaller();
            // 
            // serviceProcessInstaller1
            // 
            this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
            this.serviceProcessInstaller1.Password = null;
            this.serviceProcessInstaller1.Username = null;
            // 
            // serviceInstaller1
            // 
            this.serviceInstaller1.ServiceName = "Service1";
            this.serviceInstaller1.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
            // 
            // ProjectInstaller
            // 
            this.Installers.AddRange(new System.Configuration.Install.Installer[] {
            this.serviceProcessInstaller1,
            this.serviceInstaller1});

        }

Richard Deeming

Ошибка вполне понятна - ваш сервис не запустился достаточно быстро:
"Служба не ответила на запрос запуска или управления своевременно."

Вам нужно будет выяснить, почему ваш OnStart метод занимает так много времени. Если вы не можете заставить его работать быстрее, вам нужно будет найти другой способ запустить службу после ее установки. Или же поймать и проигнорировать исключение в serviceInstaller1_AfterInstall метод.

0 Ответов