使用ServiceHost建立WCF Console 服务器(WebService Console)
使用ServiceHost建立WCF Console 服务器(WebService Console)
RAR文件目录结构:
Source Code:
扫一扫加作者微信
创建一个Windows Console Application项目,命名为WCF_Console。
对WCF_Console添加System.EnterpriseServices和System.ServiceModel名字空间引用,然后添加WCF_Server生成的WCF项目,注意,不是引用服务,是引用项目类库WCF_PurchseModule.DLL。
然后对Host项目添加项目配置文件App.config,将WCF_Server类库中自动生成的App.config内容原封不动的全部拷贝到Host项目的App.config中。
如下图所示:
Console 主程序,启动服务:
C# Code:
public class Program
{
private static ServiceHost _ServiceHost = null;
public static void StartService()
{
Uri baseAddress = new Uri("http://localhost:8080/PurchaseSystem.svc");
//实例化ServiceHost服务器,并在构造函数中指定要发布的服务
_ServiceHost = new ServiceHost(typeof(PurchaseSystem), baseAddress);
//打开服务器,读取配置文件中的WCF服务的配置信息
_ServiceHost.Open();
}
public static void StopService()
{
if (_ServiceHost.State != CommunicationState.Closed)
_ServiceHost.Close();
}
public static void Main(string[] args)
{
StartService();
Console.WriteLine("Server is running. Press return to exit!");
Console.ReadLine();
StopService();
}
}
//来源:C/S框架网(www.csframework.com) QQ:1980854898
public class Program
{
private static ServiceHost _ServiceHost = null;
public static void StartService()
{
Uri baseAddress = new Uri("http://localhost:8080/PurchaseSystem.svc");
//实例化ServiceHost服务器,并在构造函数中指定要发布的服务
_ServiceHost = new ServiceHost(typeof(PurchaseSystem), baseAddress);
//打开服务器,读取配置文件中的WCF服务的配置信息
_ServiceHost.Open();
}
public static void StopService()
{
if (_ServiceHost.State != CommunicationState.Closed)
_ServiceHost.Close();
}
public static void Main(string[] args)
{
StartService();
Console.WriteLine("Server is running. Press return to exit!");
Console.ReadLine();
StopService();
}
}
//来源:C/S框架网(www.csframework.com) QQ:1980854898
RAR文件目录结构:
Source Code:
扫一扫加作者微信
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网