1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| using System.ServiceModel;
public class Form1
{
private ServiceHost host;
private void btServiceStart_Click(object sender, System.EventArgs e)
{
host = new ServiceHost(typeof(DevService.CurrencyService));
try {
host.Open();
this.btServiceStart.Enabled = false;
this.lblServiceState.Text = "Service is started";
}
catch (Exception ex) {
this.btServiceStart.Enabled = true;
this.lblServiceState.Text = "Service can't be started";
}
}
private void btServiceStop_Click(object sender, System.EventArgs e)
{
if (host.State == CommunicationState.Opened | host.State == CommunicationState.Faulted | host.State == CommunicationState.Opening)
{
host.Close();
this.btServiceStart.Enabled = true;
this.lblServiceState.Text = "Service is stopped";
}
}
} |
Partager