Hosting two WCF services using a single console app

后端 未结 2 493
说谎
说谎 2020-12-19 16:06

I am trying to host two services using a single console app. However, when I am trying to do so, only one service gets hosted, while the other does not.

Program.cs:<

2条回答
  •  借酒劲吻你
    2020-12-19 16:40

    You're instantly closing the first, since it's in the using. You need to set it up so the first using scope doesn't end until after the ReadLine() call.

    Try:

    using (ServiceHost host = new ServiceHost(typeof(WWWCF.Login)))
    {
         host.Open();
         Console.WriteLine("Service1 Started");
    
         using (ServiceHost host1 = new ServiceHost(typeof(WWWCF.UserRegistration)))
         {
                host1.Open();
                Console.WriteLine("Service2 Started");
                Console.ReadLine();
         }
    }
    

提交回复
热议问题