使用installutil命令安装Windows服务时出错?

时间:2017-03-23 13:08:53

标签: c# windows wcf

我会解释我到底在做什么。

第1步:

我已经使用了已添加WCF服务的一个类库文件。在这项服务中,我正在进行操作。

第2步:

我在同一解决方案中添加了Windows服务。在这项服务中,我托管了WCF服务并对其进行了调试。

所以工作正常。

第3步:

然后我使用installshied(基本msi项目)创建了这些文件的设置并安装它。它工作正常。

但我试图使用InstallUtil.exe安装它,它给出了错误。

  
    

错误讯息: -     安装程序集'C:\ Users \ Dattaprasad \ Desktop \ TestAllBrowswer \ WindowsService1.exe'。     受影响的参数是:        我=        logtoconsole =        logfile = C:\ Users \ Dattaprasad \ Desktop \ TestAllBrowswer \ WindowsService1.InstallLog        assemblypath = C:\ Users \ Dattaprasad \ Desktop \ TestAllBrowswer \ WindowsService1.exe        name = HostCompression     安装服务HostCompression ...     Service HostCompression已成功安装。     在日志应用程序中创建EventLog源HostCompression ...     System.ServiceProcess.ServiceInstaller的OnAfterInstall事件处理程序中发生异常。     System.InvalidOperationException:无法在计算机'。'上启动服务HostCompression。     抛出了内部异常System.ComponentModel.Win32Exception,并显示以下错误消息:     该服务未及时响应启动或控制请求。     回滚程序集'C:\ Users \ Dattaprasad \ Desktop \ TestAllBrowswer \ WindowsService1.exe'。     受影响的参数是:        我=        logtoconsole =        logfile = C:\ Users \ Dattaprasad \ Desktop \ TestAllBrowswer \ WindowsService1.InstallLog        assemblypath = C:\ Users \ Dattaprasad \ Desktop \ TestAllBrowswer \ WindowsService1.exe        name = HostCompression     将事件日志还原到源HostCompression的先前状态。     正在从系统中删除Service HostCompression ...     Service HostCompression已成功从系统中删除。

  

我尝试过:

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.cs文件: -

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

    }

0 个答案:

没有答案