Any program needs to run in a determined process, which is a container that contains the resources needed to run the program instance. Similarly, the monitoring and execution of a WCF service also needs to be hosted by a process. The way we create or specify a process for a WCF service is called a service Hosting. The nature of the service boarding in some way, create or specify a process to listen for requests and perform service operations on the service, providing a running environment for the service.
There are two ways in which a service is hosted: One is to create a managed application for a set of WCF services, to host the service by manually initiating the program, and all managed applications can host the WCF service, such as console applications, Windows Forms applications and ASP.net applications, and so on, we call this way of service boarding way called self-boarding (self Hosting). The other is to host the WCF service by using an existing process activation method of the operating system, which includes IIS, Windows Service, or was (Windows Process Activation Service) under Windows Process activation.
The means of service boarding is to create a ServiceHost object (or any object inherited from ServiceHostBase) for a WCF service type. Regardless of the boarding method, a series of operations are performed internally within the WCF framework during the creation of ServiceHost for a service, the most important of which is to create a service descriptionfor the service Description. In this article, we will describe the service description in a comprehensive way.
The WCF service description is represented by a type System.ServiceModel.Description.ServiceDescription, and the ServiceDescription object is a description of the WCF service runtime. In addition to some basic information about WCF services, such as the service name, namespace, and CLR type, ServiceDescription also contains a description of all service endpoints and service behaviors.
First, ServiceDescription and ServiceBehavior
As you can see from the servicedescription definition below, a series of attributes are defined in servicedescription, and their meanings are as follows:
Behaviors : A collection of service behaviors (services Behavior)
configurationname: The name of the service in the configuration file, which defaults to the full name of the service type (namespace + type name)
Name : The name of the service, which defaults to the service type name (does not contain namespaces)
Namespace : The namespace for the service, default to "http://tempuri.org/"
servicetype : CLR type of service
1:public class ServiceDescription
2: {
3: //other Members
4: Public keyedbytypecollection<iservicebehavior> behaviors {get;}
5: Public string ConfigurationName {get; set;}
6: Public serviceendpointcollection Endpoints {get;}
7: Public string Name {get; set;}
8: Public string Namespace {get; set;}
9: Public Type servicetype {get; set;}
10:}
1, Name and namespace
The name and Namespace of ServiceDescription represent the names and namespaces of the services, which are also reflected in the WSDL of the service publication. Can be set by System.ServiceModel.ServiceBehaviorAttribute's Name and Namespace properties. The default values for ServiceDescription's name and namespace are the service type names and http://tempuri.org/respectively, so the following two definitions are equivalent.
1: [ServiceBehavior]
2:public class Calculatorservice:icalculator
3: {
4: //ellipsis member
5:}
1: [ServiceBehavior (Name = "CalculatorService", Namespace = "http://tempuri.org/")]
2:public class Calculatorservice:icalculator
3: {
4: //ellipsis member
5:}
The ServiceDescription namespace maps the target namespace (targetnamespace) of the WSDL, and name directly corresponds to the <wsdl:service> node's name attribute. In the following service definition, the name and namespace are set to "Calcservice" and "http://www.artech.com/" by ServiceBehaviorAttribute. The following XML reflects the representation of the service in WSDL.
1: [ServiceBehavior (Name = "Calcservice", Namespace = "http://www.artech.com/")]
2:public class Calculatorservice:icalculator
3: {
4: //ellipsis member
5:}
1: <?xml version= "1.0" encoding= "Utf-8"?>
2: <wsdl:definitions name= "Calcservice" targetnamespace= http://www.artech.com/
3: ...>
4: ...
5: <wsdl:service name= "Calcservice" >
6: ...
7: </wsdl:service>
8: </wsdl:definitions>