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
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