WCF Study Notes 4 define service contract Contract

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.