Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用WIX安装程序安装WCF服务_C#_Wcf_Wix_Installation_Wcf Data Services - Fatal编程技术网

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

C# 使用WIX安装程序安装WCF服务,c#,wcf,wix,installation,wcf-data-services,C#,Wcf,Wix,Installation,Wcf Data Services,所做的是什么 已创建WCF服务库项目。 然后我创建了一个启动服务的主机应用程序。现在,当我双击可执行文件时,服务就启动了。 然后我添加了一个WIX项目,并添加了所需的组件 Wix代码: <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER"> <Component Id="ServiceComp" Guid="{4A6E2246-50E1-4D1B-937F-B01669E48641}">

所做的是什么

已创建WCF服务库项目。 然后我创建了一个启动服务的主机应用程序。现在,当我双击可执行文件时,服务就启动了。 然后我添加了一个WIX项目,并添加了所需的组件 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>
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>
而且,我的服务项目、托管项目和安装项目都在同一个解决方案下,但项目不同


Windows服务与WCF服务完全不同。您是否继承了System.ServiceProcess.ServiceBase并在可执行文件中实现了OnStart和OnStop方法?否。我有一个windows窗体应用程序。在这里,我创建了自己的启动和停止方法,这些方法由按钮触发;内部静态ServiceHost myServiceHost=null;私有无效按钮1\u Clickobject sender,EventArgs e{if!启动;else停止;}无效启动{if myServiceHost!=null{myServiceHost.Close;}myServiceHost=new ServiceHosttypeofService.Service1;myServiceHost.Open;label1.Text=Started….;Started=true;}}}无效停止{如果myServiceHost!=null{myServiceHost.Close;myServiceHost=null;}start=false;label1.Text=Stopped….;}不要将代码放在注释中。编辑问题并添加代码。
<?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>