WCF Study Notes 4 define service contract Contract
I learned about the architecture and basic and important concepts of the WCF system through the above learning, and learned about the WCF system through a simple example.ProgramThe development process is as follows:
1. Define a service contract
2. Implement the service contract
3. Configure the service
4. bearer service
5. implement client programs
The following describes how to define a service contract:
1. Competition between interfaces and Classes
2. Define the data types to be exchanged in the contract
3. Information exchange type
4. Security Mechanism in the contract
5. Define the input and output features of parameters in the operation.
1. Competition between interfaces and Classes
The service contract in WCF can be implemented using interface or class. The following two simple examples are as follows:
Interface:
Using system. servicemodel; </P> <p> [servicecontract] <br/> Public interface icalculator <br/> {<br/> [operationcontract] <br/> double add (double N1, double N2); <br/> [operationcontract] <br/> double subtract (double N1, double N2 ); <br/> [operationcontract] <br/> double multiply (double N1, double N2); <br/> [operationcontract] <br/> double divide (double N1, double N2); <br/>}
Class:
[Servicecontract] <br/> public class calculatorservice <br/> {<br/> [operationcontract] <br/> Public double add (double N1, double N2) <br/>{< br/> return N1 + N2; <br/>}</P> <p> [operationcontract] <br/> Public double subtract (double N1, double N2) <br/>{< br/> return N1-N2; <br/>}</P> <p> [operationcontract] <br/> Public double multiply (double N1, double N2) <br/>{< br/> return N1 * N2; <br/>}</P> <p> [operationcontract] <br/> Public double divide (double N1, double N2) <br/>{< br/> return N1/N2; <br/>}< br/>}
So what form should the contract definition use? Interface is recommended.
References:
Http://msdn.microsoft.com/en-us/library/ms733070 (V = vs.90). aspx