WCF中ServiceHost能不能host多个服务?

现在我有两个Service类:
UserService
DictionaryService

配置文件是:

  <system.serviceModel>
    
<services>
      
<service name="DictionaryServer.Dal.UserService">
        
<endpoint address="net.tcp://localhost:8001/UserService"
                   binding
="netTcpBinding"
           contract
="Common.Interface.IUserService" >
        
</endpoint>
      
</service>
      
<service name="DictionaryServer.Dal.DictionaryService">
        
<endpoint address="net.tcp://localhost:8001/DictionaryService"
                   binding
="netTcpBinding"
           contract
="Common.Interface.IDictionaryService" >
        
</endpoint>
      
</service>
    
</services>
  
</system.serviceModel>

以下是我目前的解决方案:

    class Program
    
{
        
static void Main(string[] args)
        
{
            ServiceHost host1 
= new ServiceHost(typeof(UserService));
            ServiceHost host2 
= new ServiceHost(typeof(DictionaryService));
            host1.Open();
            host2.Open();
            Console.WriteLine(
"The service is ready.");
            Console.ReadLine();
            host1.Close();
            host2.Close();
        }

    }


我的问题就是能不能只用一个ServiceHost实例,来加载两个服务类?
要是用我现在这样的实现方案的话,有许多服务类的话,岂不是打开好多个ServiceHost?

posted @ 2007-02-21 01:00  Stanley.Luo  阅读(6018)  评论(8编辑  收藏  举报