0

いくつかの WCF サービスをホストする Windows サービスを作成しました
が、開始すると次のメッセージが表示されて停止します。 ここに画像の説明を入力

Windows ログ ビューアーを確認しましたが、エラーはありません

以前にコンソールアプリケーションですべてをテストしましたが、動作しています。

私のコードは次のとおりです。

ServiceHost host1;
ServiceHost host2;
ServiceHost host3;

public ServicesHost()
{
    InitializeComponent();
}

protected override void OnStart(string[] args)
{
    if (host1 != null)            
        host1.Close();
    if (host2 != null)
        host2.Close();
    if (host3 != null)
        host3.Close();            
    host1 = new ServiceHost(typeof(Service1));
    host1.Open();    
    host2 = new ServiceHost(typeof(Service2));
    host2.Open();    
    host3 = new ServiceHost(typeof(Service3));
    host3.Open();                       
}

protected override void OnStop()
{
    host1.Close();
    host1 = null;
    host2.Close();
    host2 = null;
    host3.Close();
    host3 = null;
}        

app.config:

<?xml version="1.0" encoding="utf-8" ?>

  <service behaviorConfiguration="MyServiceBehavior"
           name="Service2">
    <endpoint address=""
              binding="basicHttpBinding"
              contract="IService2">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding"
              contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8732/Service2" />
      </baseAddresses>
    </host>
  </service>

  <service behaviorConfiguration="MyServiceBehavior"
           name="Service3">
    <endpoint address=""
              binding="basicHttpBinding"
              contract="IService3">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding"
              contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8733/Service3" />
      </baseAddresses>
    </host>
  </service>

</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="MyServiceBehavior">
      <serviceMetadata httpGetEnabled="True"/>
      <serviceDebug includeExceptionDetailInFaults="True" />
    </behavior>
  </serviceBehaviors>
</behaviors>

編集:私はインストーラーを持っています:

[RunInstaller(true)]
public partial class ServiceInstaller : System.Configuration.Install.Installer
{
    private System.ServiceProcess.ServiceProcessInstaller process;
    private System.ServiceProcess.ServiceInstaller service;

    public ServiceInstaller()
    {            
        process = new System.ServiceProcess.ServiceProcessInstaller();
        process.Account = System.ServiceProcess.ServiceAccount.NetworkService;
        service = new System.ServiceProcess.ServiceInstaller();
        service.ServiceName = "WCFHostService";
        service.DisplayName = "WCFHostService";
        service.Description = "WCF Service Hosted";
        service.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
        Installers.Add(process);
        Installers.Add(service);
    }
}
4

2 に答える 2

0

まあ、あなたはまったくログに記録していません。ウィンドウ サービスには、運用/保守フェーズで生き残るための優れたログ システムが必要です。ログイン システムを追加し、最初に try catch を配置し、例外をキャッチしてファイルに記録します。これは、現在直面している問題を解決するのに役立ちますが、プロジェクトの存続期間中は毎日役立ちます。

于 2013-09-19T10:15:15.683 に答える