Wcf用代码启动Server

1.创建一个Wcf服务库,工程名为WcfLib,服务名为Service1(默认就是Service1)
2.创建一个Console或WinFrom工程,手动加入对System.ServiceModel的引用,然后创建一个新线程,最后让新线程执行以下代码:

try
{
    ServiceHost newService = new ServiceHost(typeof(WcfLib.Service1));
    newService.Open();
    Console.WriteLine("WCF服务启动成功。");
}
catch (System.Exception ex)
{
    Console.WriteLine("WCF服务启动失败,原因:" + ex.Message);
}
原文地址:https://www.cnblogs.com/xxxteam/p/2889104.html