使用WIX安装程序安装WCF服务

时间:2014-11-02 07:45:54

标签: c# wcf wix installer wcf-data-services

做了什么;

  1. 创建了一个WCF服务库项目。
  2. 然后我创建了一个启动服务的主机应用程序。现在,当我双击可执行文件时,服务就会启动。
  3. 然后我添加了一个WIX项目并添加了所需的组件
  4. Wix代码:

    <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
          <Component Id="ServiceComp" Guid="{4A6E2246-50E1-4D1B-937F-B01669E48641}">
            <File Id="Service.dll" Name="Service.dll" Source="..\ServiceHost\bin\Debug\Service.dll"/>
            <File Id="ServiceHost.exe" Name="ServiceHost.exe" Source="..\ServiceHost\bin\Debug\ServiceHost.exe"/>
            <File Id="ServiceHost.exe.config" Name="ServiceHost.exe.config" Source="..\ServiceHost\bin\Debug\ServiceHost.exe.config"/>
            <ServiceInstall Id="MYServiceInstaller" Type="ownProcess" Name="MYService" DisplayName=" MYSStartService " Description="MY Service Component" Start="auto" Account="LocalSystem" ErrorControl="critical" />
            <ServiceControl Id="MYSStartService" Start="install" Stop="both" Remove="uninstall" Name="MYService" Wait="yes" />
          </Component>
            </ComponentGroup>
    

    现在,当我运行设置时,它会生成错误

    enter image description here

    我也尝试了以下内容,

    • 我添加了一个Windows服务项目
    • 引用了服务项目(引用了dll文件)。
    • 添加了安装程序(进程,服务)并对其进行了配置。
    • 然后在wix中做了同样的事。

    我仍然遇到同样的问题。

    现在我的问题是:

    • 我应该在WiX文件中将<ServiceInstall><ServiceControl>个标记放在哪里? (它们应该位于可执行文件所在的组件块中还是位于任何位置?)
    • 安装过程中可能导致问题的原因是什么?
    • 如何为WCFLibrary项目创建WiX设置文件?
    • 我是否错过了任何需要包含的内容?

    请帮助我。

    以下是启动和停止服务的Windows窗体应用程序的代码:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.ServiceModel;
    
    
    namespace ServiceWinHost
    {
        public partial class Form1 : Form
        {
            bool started = false;
            internal static ServiceHost myServiceHost = null; 
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                if (!started)
                    Start();
                else
                    Stop();
            }
    
            void Start() {
                try
                {
                    if (myServiceHost != null)
                    {
                        myServiceHost.Close();
                    }
                    myServiceHost = new ServiceHost(typeof(Service.Service1));
                    myServiceHost.Open();
    
                    label1.Text = "Started....";
                    started = true;
                }
                catch (Exception ex)
                {
                    label1.Text = ex.ToString();
                }
            }
    
            void Stop() {
    
            try
            {
                if (myServiceHost != null)
                {
                    myServiceHost.Close();
                    myServiceHost = null;
                }
                started = false;
                label1.Text = "Stopped....";
            }
            catch (Exception ex)
            {
                label1.Text = ex.ToString();
            }
            }
        }
    }
    

    wix文件完整代码:

    <?xml version="1.0" encoding="UTF-8"?>
    <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
        <Product Id="*" Name="ServiceWinSetup" Language="1033" Version="1.0.0.0" Manufacturer="Service Host" UpgradeCode="b9c11d77-b587-4f24-ba49-3a4031a35652">
            <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
    
            <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
            <!--<MediaTemplate />-->
    
            <Feature Id="ProductFeature" Title="ServiceWinSetup" Level="1">
                <ComponentGroupRef Id="ProductComponents" />
            </Feature>
        <UIRef Id="WixUI_ErrorProgressText" />
        <UIRef Id="WixUI_Common" />
        <UIRef Id="WixUI_FeatureTree" />
        </Product>
    
        <Fragment>
        <Media Id="1" Cabinet="media1.cab" EmbedCab="yes" CompressionLevel="high" />
            <Directory Id="TARGETDIR" Name="SourceDir">
                <Directory Id="ProgramFilesFolder">
                    <Directory Id="INSTALLFOLDER" Name="ServiceWinSetup" />
                </Directory>
            </Directory>
        </Fragment>
    
        <Fragment>
            <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
          <Component Id="ServiceComp" Guid="{4A6E2246-50E1-4D1B-937F-B01669E48641}">
            <File Id="Service.dll" Name="Service.dll" Source="..\ServiceWinInstall\bin\Debug\Service.dll"/>
            <File Id="ServiceWinInstall.exe" Name="ServiceWinInstall.exe" Source="..\ServiceWinInstall\bin\Debug\ServiceWinInstall.exe"/>
            <File Id="ServiceWinInstall.exe.config" Name="ServiceWinInstall.exe.config" Source="..\ServiceWinInstall\bin\Debug\ServiceWinInstall.exe.config"/>
            <ServiceInstall Id="MYSERVICE" Type="ownProcess" Name="MyService" DisplayName="My own ervice" Description="just for test" Start="auto" Account="LocalSystem" ErrorControl="critical" />
            <ServiceControl Id="MYSERVICEStartService" Start="install" Stop="both" Remove="uninstall" Name="MyService" Wait="yes" />
          </Component>
            </ComponentGroup>
        </Fragment>
    </Wix>
    

    而且,我的服务项目,托管项目和设置项目都在相同的解决方案下但不同的项目

    enter image description here

0 个答案:

没有答案