2017-01-27 19 views
0

私はWCFサービスをホストしているC#アプリケーションを持っています。アプリケーションでボタンクリックイベントを追加して、サービスが実行中かホストされているかをユーザーに知らせたいと思います。サービスが実行/ホストされているかどうかを検出する方法はありますか?WCFサービスがホストで実行されているかどうかを確認する方法

誰かがここで私はホスティングサービスを開始するために使用していたコードがあり、それを見たい場合:

 private static void RunService() 
    { 
     System.ServiceModel.ServiceHost host = new System.ServiceModel.ServiceHost(typeof(AccountingOperationsService.AccountingOperationsService)); 
     System.ServiceModel.Description.ServiceDebugBehavior debug = host.Description.Behaviors.Find<System.ServiceModel.Description.ServiceDebugBehavior>(); 
     // if not found - add behavior with setting turned on 
     if (debug == null) 
     { 
      host.Description.Behaviors.Add(
       new System.ServiceModel.Description.ServiceDebugBehavior() { IncludeExceptionDetailInFaults = true }); 
     } 
     else 
     { 
      // make sure setting is turned ON 
      if (!debug.IncludeExceptionDetailInFaults) 
      { 
       debug.IncludeExceptionDetailInFaults = true; 
      } 
     } 
     try 
     { 
      host.Open(); 


     } 
     catch (Exception ex) 
     { 

      string errorMessage = ex.Message + Environment.NewLine; 
      errorMessage += ex.StackTrace + Environment.NewLine; 

      DevExpress.XtraEditors.XtraMessageBox.Show(errorMessage, "Error Starting Service", MessageBoxButtons.OK, MessageBoxIcon.Error); 
     } 

答えて

4

おそらく、あなたは、WCFサービスでメソッドPingを作成する必要があります。

public bool Ping() 
{ 
    return true; 
} 

とアプリケーションの呼び出しでPing

bool itsWork; 
try 
{ 
    itsWork = service.Ping(); 
} 
catch(Exception ex){} 
関連する問題