※IDC知识库搜索

当前位置: 服务器托管 > IT学院 > 操作系统 >

托管(4)

WCF也允许开发者在宿主配置文件中列出基地址内容: system.serviceModel services service name = MyNamespace.MyService host baseAddresses add baseAddress = net.tcp://localhost:8001//


WCF也允许开发者在宿主配置文件中列出基地址内容:

<system.serviceModel>
<services>       <service name = "MyNamespace.MyService">          <host>             <baseAddresses>                <add baseAddress = "net.tcp://localhost:8001/"/>                <add baseAddress = "http://localhost:8002/"/>             </baseAddresses>          </host>          ...       </service>    </services> </system.serviceModel>

创建宿主时,无论在配置文件中找到哪一个基地址,宿主都会使用它,同时还要加上以编程方式提供的基地址。需要特别注意,我们必须确保配置的基地址的样式不能与代码中的基地址的样式重叠。
我们甚至可以针对相同的类型注册多个宿主,只要这些宿主使用了不同的基地址:

Uri baseAddress1  = new Uri("net.tcp://localhost:8001/");
ServiceHost host1 = new ServiceHost(typeof(MyService),baseAddress1);
host1.Open();
Uri baseAddress2 = new Uri("net.tcp://localhost:8002/");
ServiceHost host2 = new ServiceHost(typeof(MyService),baseAddress2);
host2.Open();
然而,这并不包括第8章介绍的使用线程的情况,以这种方式打开多个宿主并无优势可言。此外,如果基地址是配置文件提供的,那么就需要使用ServiceHost的构造函数为相同的类型打开多个宿主。

托管的高级特性

ServiceHost实现的ICommunicationObject接口定义了一些高级特性,如例1-4所示。

例1-4:ICommunicationObject接口
public interface ICommunicationObject
{
void Open();
void Close();
void Abort();
event EventHandler Closed;
event EventHandler Closing;
event EventHandler Faulted;
event EventHandler Opened;
event EventHandler Opening;
IAsyncResult BeginClose(AsyncCallback callback,object state);
IAsyncResult BeginOpen(AsyncCallback callback,object state);
void EndClose(IAsyncResult result);
void EndOpen(IAsyncResult result);
CommunicationState State
{get;}
//更多成员
}
public enum CommunicationState
{
Created,
Opening,
Opened,
Closing,
Closed,
Faulted
}

北京双线机房 北京双线服务器 北京双线主机托管 北京双线托管 服务器托管 托管服务器
关于我们| 招聘信息| 联系我们| 付款方式| 网站地图 |友情链接 | 云计算服务平台 | 在线工单系统
咨询热线:010-82894410/82894420  7×24小时技术支持:13811155188 15811155188
传真:010-82894410转607  客服传真:010-82894410转607   京ICP证090528号 京ICP备09042719号 公安局备案编号:1101083278 
Copyright© 2006-2010 东方瑞庭(TopServers) 版权所有