I have a WCF application that has two Services that I am trying to host in a single Windows Service using net.tcp. I can run either of the services just fine, but as soon as I t
Base your service on this MSDN article and create two service hosts. But instead of actually calling each service host directly, you can break it out to as many classes as you want which defines each service you want to run:
internal class MyWCFService1
{
internal static System.ServiceModel.ServiceHost serviceHost = null;
internal static void StartService()
{
if (serviceHost != null)
{
serviceHost.Close();
}
// Instantiate new ServiceHost.
serviceHost = new System.ServiceModel.ServiceHost(typeof(MyService1));
// Open myServiceHost.
serviceHost.Open();
}
internal static void StopService()
{
if (serviceHost != null)
{
serviceHost.Close();
serviceHost = null;
}
}
};
In the body of the windows service host, call the different classes:
// Start the Windows service.
protected override void OnStart( string[] args )
{
// Call all the set up WCF services...
MyWCFService1.StartService();
//MyWCFService2.StartService();
//MyWCFService3.StartService();
}
Then you can add as many WCF services as you like to one windows service host.
REMEBER to call the stop methods as well....