Wcf hosting

WCF Hosting :

  1. IIS hosting
  2. Self hosting
  3. Windows Activation Service
  4. Windows Service
In the Windows Service hosting
we need to add one installer in the host app follow the steps:
ServiceHost hostobj = new ServiceHost(typeof(WcfServiceWindowsService.Service1));

protected override void OnStart(string[] args)
{
if (hostobj!=null)
{
hostobj.Close();
}
hostobj.Open();
}

protected override void OnStop()
{
if (hostobj!=null)
{
hostobj.Close();
hostobj = null;

}
}

//////////////////////////////////////////////////////////////////////////////////////////
create the installer code as follows :
  [RunInstaller(true)]
public class ProjectInstaller : Installer
{
private ServiceProcessInstaller process;
private ServiceInstaller service;

public ProjectInstaller()
{
process = new ServiceProcessInstaller();
process.Account = ServiceAccount.LocalSystem;
service = new ServiceInstaller();
service.ServiceName = “WcfServiceWindowsService”;
Installers.Add(process);
Installers.Add(service);
}
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s