Windows Communication Foundation (WCF) applications need to have a runtime environment for the management of its object's lifecycle. The host process models allows is a new concept in WCF referring to WCF hosting environment which can have several services, and the same service can be hosted in several host processes. Having a separate process is immaterial who provides the process or what kind of a process is involved. The host can be provided by IIS, by the Widows Activation Service (WAS) on Windows Vista, or by the developer as part of the application.
IIS Hosting is the environment managed by Microsoft Internet Information Server (IIS) web server. This host process is launched automatically upon the first client request, and you rely on IIS to manage the life cycle of the host process and the underlying service's life cycle. The main disadvantage of IIS hosting is that you can only use HTTP services and the restriction of having all services use the same port number. Hosting in IIS is very similar to hosting a classic ASMX web service. You need to create a virtual directory under IIS and supply a service component. In WCF naming convention, you must add the svc extension to the service component's file.
Self Hosting is the environment managed by any Windows process, such as a Windows Forms application, a Console application, or a Windows NT Service. Note that the process must be running before the client calls the service, which typically means you have to pre-launch it, as shown in Listing 1. This is not an issue for NT Services or in-proc.
using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
namespace WCFConsoleApplication
{
internal class MyServiceHost
{
internal static ServiceHost myServiceHost = null;
internal static void StartService()
{
// Consider putting the baseAddress in the configuration system
// and getting it here with AppSettings
Uri baseAddress = new Uri("http://localhost:8080/WCFConsoleApplication/testservice");
// Instantiate new ServiceHost
myServiceHost = new ServiceHost(typeof(testservice), baseAddress);
myServiceHost.Open();
}
internal static void StopService()
{
// Call StopService from your shutdown logic (i.e. dispose method)
if (myServiceHost.State != CommunicationState.Closed)
myServiceHost.Close();
}
}
class Program
{
static void
{
}
}

Manjunath BEPosted Mar 15, 2011, 1:37 AM
Hi Can you explain how to host WCF service in WAS with net.Tcp binding. My email adress is [email protected]