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);
}