Hosting two WCF services using a single console app

后端 未结 2 495
说谎
说谎 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:23

    Your first service jumps out of the using block and so is disposing too early. Try this...

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

    Take a look at this: http://msdn.microsoft.com/en-us//library/yh598w02.aspx

提交回复
热议问题