Chapter 2: WCF Basics (3)

Original: http://www.wcftutorial.net/Introduction-to-WCF.aspx

Contracts and Service Host Contracts and Service Host

Contracts
In WCF, all services are published through contracts, which are platform-independent , used to describe the role of the service, there are 4 main contracts in WCF.

Service Contract Service Contract
The service contract describes the operations that the service can provide. For example, a service that confirms the temperature of the city by zip code, this service is the service contract, which can be serviced by characteristics and operation contract attributes.

Learn more through the service

contract
Data Contract The Data Contract describes the data type published to the client, defines the data type that the service accepts and responds to, int, string These types are defined in the XML schema, so the client can Recognized, but the custom class or data type cannot be recognized by the client, for example, the Employee type, by using the data contract, the client can be notified to accept or return the custom type.

Learn more through Data

Contracts
Message Contracts Message Contract WCF uses the default SOAP protocol to communicate between client and server. If this does not meet your needs, you can customize the message format, which can be achieved using the message contract properties.

Learn more through

Message Contracts Fault Contract
In the call of the client application, there is a problem on the server side. I want to get the specific reason for the problem. How can I get this error message? To do this, we have to use the error contract. The error contract is responsible for providing documentation to the client when an error occurs, which will make it easy for us to understand the reason for the error.

Learn more through Error Contract

Service
Managed Service Managed Object Service Host is a process that hosts a WCF service, and registers the endpoint, it will load the configuration file of the file point, apply the setting, and listen for requests, named System.ServiceModel.ServiceHost Spaces have these types, and these objects are created by WCF self-hosted services.

The following example is a console application using self-hosting to create a WCF service.

//Creating uri for the hosting the service  
Uri uri = new Uri("http://localhost/CategoryService");  
//Creating the host object for MathService  
ServiceHost host = new ServiceHost(typeof(CategoryService), uri);  
//Adding endpoint to the Host object  
host.AddServiceEndpoint(typeof(ICategoryService),new WSHttpBinding(), uri);  
host.Open(); //Hosting the Service  
Console.WriteLine("Waiting for client invocations");  
Console.ReadLine();  
host.Close();

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326847536&siteId=291194637