How to:implement a Windows communication Foundation Service contract

Source: Internet
Author: User

The second of six tasks required to create a basic Windows communication Foundation (WCF) service and a client tha T can call the service. for a overview of all six tasks, see the Getting Started Tutorial topic.

The next step in creating a WCF application are to implement the service interface. This involves creating a class called CalculatorService that implements the User-defined ICalculator interface ..

To implement a WCF service contract
    • Open the Service1.cs or Service1.vb file and add the following code:

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Runtime.Serialization;usingSystem.ServiceModel;usingSystem.Text;namespacegettingstartedlib{ Public classCalculatorservice:icalculator { Public DoubleADD (DoubleN1,Doublen2) {            Doubleresult = N1 +N2; Console.WriteLine ("Received Add ({0},{1})", N1, N2); //Code added to write output to the console window.Console.WriteLine ("Return: {0}", result); returnresult; }         Public DoubleSubtract (DoubleN1,Doublen2) {            Doubleresult = N1-N2; Console.WriteLine ("Received Subtract ({0},{1})", N1, N2); Console.WriteLine ("Return: {0}", result); returnresult; }         Public DoubleMultiply (DoubleN1,Doublen2) {            Doubleresult = N1 *N2; Console.WriteLine ("Received Multiply ({0},{1})", N1, N2); Console.WriteLine ("Return: {0}", result); returnresult; }         Public DoubleDivide (DoubleN1,Doublen2) {            Doubleresult = N1/N2; Console.WriteLine ("Received Divide ({0},{1})", N1, N2); Console.WriteLine ("Return: {0}", result); returnresult; }    }}

Each method implements the calculator operation and writes some text to the console to make testing easier.

How to:implement a Windows communication Foundation Service contract

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.