在使用Visual Studio2010创建一个WCF工程后,在同一个Solution中添加一个调用工程,将WCF服务的引用添加到调用的工程中
Type serviceType = typeof(WcfServiceLibrary1.Service1 );
using (ServiceHost serviceHost = new ServiceHost(serviceType))
{
serviceHost.Open();
Console .WriteLine ("Is working");
Console.ReadKey(true);
serviceHost.Close();
}
要使serviceHost.Open()成功需要将WCF工程中的配置文件复制一份到调用工程中,baseAddress端口号改成不一样的即可。