ServiceHost 类
来源:互联网 发布:军团战争怪物数据 编辑:程序博客网 时间:2024/05/09 20:38
提供服务的主机。
实现 服务模型编程模型所使用的主机。
当您没有使用 Internet 信息服务 (IIS) 或 Windows 激活服务 (WAS) 公开服务时,请使用ServiceHost 类来配置和公开服务以供客户端应用程序使用。IIS 和 WAS 均代表您与ServiceHost 对象交互。
若要公开一项服务以供调用方使用, 需要完整的服务说明(由 ServiceDescription 类表示)。ServiceHost 类根据服务类型和配置信息创建 ServiceDescription,然后再使用该说明为说明中的每个终结点创建ChannelDispatcher 对象。
使用 ServiceHost 对象加载服务、配置终结点、应用安全设置并启用侦听程序来处理传入的请求。
public static void Main()
{
using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService)))
{
try
{
// Open the ServiceHost to start listening for messages.
serviceHost.Open();
// The service can now be accessed.
Console.WriteLine("The service is ready.");
Console.WriteLine("Press <ENTER> to terminate service.");
Console.ReadLine();
// Close the ServiceHost.
serviceHost.Close();
}
catch (TimeoutException timeProblem)
{
Console.WriteLine(timeProblem.Message);
Console.ReadLine();
}
catch (CommunicationException commProblem)
{
Console.WriteLine(commProblem.Message);
Console.ReadLine();
}
}
}
http://blog.csdn.net/dyllove98/article/details/9631427
using (ServiceHost host = new ServiceHost(typeof(CalculatorService)))
{
host.AddServiceEndpoint(
typeof(ICalculator),
new WSHttpBinding(),
"http://127.0.0.1:1111/CalculatorService");
if (host.Description.Behaviors.Find<ServiceMetadataBehavior>() == null)
{
ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
behavior.HttpGetEnabled = true;
behavior.HttpGetUrl = new Uri("http://127.0.0.1:1111/CalculatorService/metadata");
host.Description.Behaviors.Add(behavior);
}
host.Opened += delegate
{
Console.Write("CalculatorService已经启动,按任意键终止服务");
};
host.Open();
Console.Read();
}
- ServiceHost 类
- 通过继承ServiceHost编写简化MEX编程的类
- WCF调试异常信息:ServiceHost 仅支持类服务类型
- WCF 学习笔记: ServiceHost
- WCF中的ServiceHost初始化两种方式
- WCF中的ServiceHost初始化两种方式
- WCF ServiceHost的实例方式及ServiceHost实例的并发方式
- Wcf 基础教程 服务寄宿之编码实现 ServiceHost
- Wcf 基础教程 服务寄宿之编码实现 ServiceHost
- WCF 项目应用连载[4] - 自定义配置 扩展ServiceHost - LServiceHost
- WCF学习(2) ServiceHost寄宿多个服务
- 解决开ServiceHost时候System.PlatformNotSupportedException: Operation is not supported on this platform.
- WCF 找不到类型“WcfServiceStudy.WcfService”,它在 ServiceHost 指令中提供为 Servi
- 找不到类型“ITOO.AuthorityBackRole.WCFService.AuthorityBackRoleManageService”,它在 ServiceHost 指令中提供为 Servic
- 通信对象 System.ServiceModel.ServiceHost 无法用于通信,因为其处于“出错”状态。
- 通信对象 System.ServiceModel.ServiceHost 无法用于通信,因为其处于“出错”状态。
- WCF中 改名后 无法找到 ServiceHost 指令中作为服务属性值提供的类型“WCFDemo.Service1”。
- 找不到类型*它在 ServiceHost 指令中提供为 Service 特性值,或在配置元素 *serviceModel/serviceHostingEnvironment/serviceActiva
- [iOS翻译]《The Swift Programming Language》系列:Welcome to Swift-01
- Android.mk的用法和基础
- OCP 1Z0 051 QUESTION NO: 26
- IE6 location.href不跳转
- 【转】TCP协议中的三次握手和四次挥手(图解)
- ServiceHost 类
- AOJ-AHU-OJ-517 序列(贪心)
- JSP的application对象
- 经纬财富:南宁现货白银k线分析
- 去除c/c++代码中的注释
- spring JSONP
- error: initializer element is not constant
- makefile模块编译模板
- OCP 1Z0 051 QUESTION NO: 27