クライアント アプリケーションにデータをフィードするための Windows サービスを作成しました。クライアントは、同じサーバー上で実行され、別々のデータベースを指すように構成されたこのサービスの 2 つのインスタンスを必要とする楽しい構成要求を思いつきました。
これまでのところ、私はこれを実現することができず、仲間のスタックオーバーフロー メンバーがその理由についていくつかのヒントを提供できることを期待していました。
現在のセットアップ:
Windows サービスを含むプロジェクトをセットアップしました。これ以降は AppService と呼びます。カスタム インストール手順を処理する ProjectInstaller.cs ファイルは、App.config のキーに基づいてサービス名を設定します。 :
this.serviceInstaller1.ServiceName = Util.ServiceName;
this.serviceInstaller1.DisplayName = Util.ServiceName;
this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
この場合、Util は構成ファイルからサービス名をロードする単なる静的クラスです。
ここから先は、両方のサービスをインストールするために 2 つの異なる方法を試しましたが、どちらも同じ方法で失敗しました。
最初の方法は、サービスの最初のコピーをインストールし、インストールされたディレクトリをコピーして名前を変更し、アプリの構成を変更して目的のサービス名を変更した後、次のコマンドを実行することでした。
InstallUtil.exe /i AppService.exe
それがうまくいかなかったとき、私は 2 番目のインストーラー プロジェクトを作成しようとし、構成ファイルを編集して 2 番目のインストーラーをビルドしました。インストーラーを実行すると問題なく動作しましたが、services.msc にサービスが表示されなかったため、2 番目にインストールされたコード ベースに対して前のコマンドを実行しました。
どちらの場合も、InstallUtil から次の出力を受け取りました (関連部分のみ)。
トランザクション インストールの実行。
インストールのインストール フェーズの開始。
サービス App Service Two をインストールしています... サービス App Service Two が正常にインストールされました。EventLog ソース App Service Two をログ アプリケーションに作成しています...
インストール フェーズ中に例外が発生しました。System.NullReferenceException: オブジェクト参照がオブジェクトのインスタンスに設定されていません。
インストールのロールバック フェーズが開始されます。
ソース App Service Two のイベント ログを以前の状態に復元しています。Service App Service Two is being removed from the system... Service App Service Two はシステムから正常に削除されました。
ロールバック フェーズが正常に完了しました。
トランザクションのインストールが完了しました。インストールに失敗し、ロールバックが実行されました。
十分な関連情報があることを確認したかったので、長々とした投稿で申し訳ありません。これまでのところ私が困惑しているのは、サービスのインストールが正常に完了し、NullReferenceException がスローされたように見える EventLog ソースを作成した後であると記載されていることです。だから、誰かが私が間違っていることを知っているか、より良いアプローチを持っているなら、それは大歓迎です。