Click here to Skip to main content
15,887,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.



Error Message:
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.


What I have tried:

Service1.cs file:-
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.cs class

[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});

        }
Posted
Comments
Richard Deeming 23-Mar-17 12:01pm    
The error is quite clear - your service didn't start quickly enough:
"The service did not respond to the start or control request in a timely fashion."

You'll need to find out why your OnStart method is taking so long. If you can't make it run any faster, you'll need to find another way to start the service after you've installed it. Or, catch and ignore the exception in the serviceInstaller1_AfterInstall method.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900