program.cs

来自「C#高级编程第6版随书源代码 值得下载」· CS 代码 · 共 39 行

CS
39
字号
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

namespace Wrox.ProCSharp.WCF
{
   class Program
   {
      internal static ServiceHost myServiceHost = null;

      internal static void StartService()
      {
         //Instantiate new ServiceHost 
         myServiceHost = new ServiceHost(typeof(Wrox.ProCSharp.WCF.MessageService));

         //Open myServiceHost
         myServiceHost.Open();
      }

      internal static void StopService()
      {
         //Call StopService from your shutdown logic (i.e. dispose method)
         if (myServiceHost.State != CommunicationState.Closed)
            myServiceHost.Close();
      }

      static void Main()
      {
         StartService();
         Console.WriteLine("Service running; press return to exit");
         Console.ReadLine();
         StopService();
         Console.WriteLine("stopped");
      }
   }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?