Wcf用代码启动Server

it2026-04-04  6

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/archive/2013/02/01/2889104.html

最新回复(0)