tags:

views:

77

answers:

3

Hi All, I want to know what happens when I create an instance of a ServiceHost class? What it does ?

+1  A: 

Hi,

Typically the ServiceHost class is used to host your WCF services in a standalone app (such as a console app), if you are not using IIS or Windows Activation Service (WAS).

In simple terms it will deal with the COMs (listening for messages for a particular service).

You can also derive from ServiceHost to add customization if required, in combination with a specialization of ServiceHostFactory.

See MSDN example.

HTH

Phil'

Philip
A: 

It creates channels that are responsible for things like reliable transfer and security. It listens for incoming messages and calls your operation methods.

Petar Repac
+1  A: 

The ServiceHost (whether instantiated by yourself directly, or whether you delegate that job to IIS/WAS) is the runtime environment for your WCF class - which is just a simple .NET class after all (which needs to run somewhere).

The ServiceHost basically provides all the "plumbing" around your WCF service - creating the endpoints and the listeners on those endpoints to listen for messages and catch those as they come in; it provides the whole channel stack from the transport level through all the layers of WCF up through deserializers on to the dispatcher which then decides which class and which method on that class to call, and so on.

In WCF, in your service class, you write only the actual busienss logic of your service - the ServiceHost and all its classes around it handle all the nitty-gritty details of the receiving of messages and sending back of responses etc.

Marc

marc_s