ServiceHost
Regardless of the hosting environment, the service model provides a consistent runtime
experience for host initialization, operation calls, and message processing. The ServiceHost type, part of the System.ServiceModel namespace, is the centerpiece of this hosting story. All
WCF services must be associated with a ServiceHost
instance to be accessible at runtime. Figure 4-1 illustrates the
allocation of ServiceHost and associated service types
for Windows service and IIS hosting.

Figure 4-1. Each ServiceHost is always associated with a particular service type
Each ServiceHost instance is initialized with
information about the service type, one or more service endpoints, optional base addresses,
and behaviors that govern how the service model processes requests to the service. In this
section, I’ll explain the mechanics of the ServiceHost.
Initializing the ServiceHost
Example 4-1 illustrates a simple
example of a console host application initializing the ServiceHost programmatically. In fact, this is the entire listing for the
host application. When the application is launched, the ServiceHost is constructed with the service type, HelloIndigo.HelloIndigoService. A single endpoint is created, exposing its
operations from the HelloIndigo.IHelloIndigoService
service contract over NetTcpBinding. Recall from the
introduction to these concepts in Chapter 1 that when a complete URI ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access