2

私は C# や .NET の専門家ではありません。でも使わなきゃいけない…

InstallUtil.exe MyService.exe基本的に WCF サービスを実行している Windows サービスをインストールするために実行しています。私は WFC インターフェイスを定義し、それを実装しました。以下はインターフェースです。

[ServiceContract(Namespace = "http://WCFService", Name = "WCFService")]
public interface IWCFService
{
    [OperationContract]
    User Login(string userName, string password);

    [OperationContract]
    List<Project> GetProjects(Guid userGuid);

    [OperationContract]
    List<Stylesheet> GetStylesheets(Guid projectGuid);

}

また、次のように Windows サービスを定義しました。

public partial class Service: ServiceBase
{
    public FlatWsdlServiceHost m_fwsh = null; // extends ServiceHost

    public DesignerService()
    {
        InitializeComponent();
    }

    protected override void OnStart(string[] args)
    {

        this.EventLog.WriteEntry("OnStart Successfull", EventLogEntryType.Information);

        if (m_fwsh != null)
        {
            m_fwsh.Close();
        }

        // Create a ServiceHost for the EventWebService type and 
        // provide the base address.
        Uri localUri= new Uri("http://localhost:7777/");
        m_fwsh = new FlatWsdlServiceHost(typeof(WCFService), localUri);

        // Open the ServiceHostBase to create listeners and start 
        // listening for messages.
        m_fwsh.Open();
    }

    protected override void OnStop()
    {
        //base.OnStop();

        if (m_fwsh != null)
        {
            m_fwsh.Close();
            m_fwsh = null;
        }
    }

    protected override void OnPause()
    {
        base.OnPause();
    }
}

InstallUtil.exe MyService.exeログを実行すると、次のように表示されます。

Installing assembly 'MyService.exe'.
Affected parameters are:
   logtoconsole = 
   logfile = MyService.InstallLog
   assemblypath = MyService.exe
No public installers with the RunInstallerAttribute.Yes attribute could be found in the MyService.exe assembly.
Committing assembly 'MyService.exe'.
Affected parameters are:
   logtoconsole = 
   logfile = MyService.InstallLog
   assemblypath = MyService.exe
No public installers with the RunInstallerAttribute.Yes attribute could be found in the MyService.exe assembly.
Remove InstallState file because there are no installers.

また、serviceInstaller1 と serviceProcessInstaller1 を初期化する ProjectInstaller.cs もあります。WCF サービスを追加する前は、Windows サービスは正常にインストールされ、「OnStart Successful」メッセージが Windows ログに書き込まれていました。

どんな助けや提案も大歓迎です。

4

1 に答える 1

5

次のようなクラスが必要です。

// Provide the ProjectInstaller class which allows 
// the service to be installed by the Installutil.exe tool
[RunInstaller(true)]
public class ProjectInstaller : Installer
{
    private ServiceProcessInstaller process;
    private ServiceInstaller service;

    public ProjectInstaller()
    {
        process = new ServiceProcessInstaller();
        process.Account = ServiceAccount.LocalSystem;
        service = new ServiceInstaller();
        service.ServiceName = "WCFWindowsServiceSample";
        Installers.Add(process);
        Installers.Add(service);
    }
}

完全なチュートリアルはMSDNにあります

于 2013-04-16T18:32:12.303 に答える