Proxy > Gmail Facebook Yahoo!

Implementing Service Contract in WCF




The IArea interface, created as service contract in the previous tutorial:Defining Service contract in WCF, defines the basic functionality of the WCF service that will be exposed as service methods. The interface just outlines the operation contracts as part of service contract which need implementation of methods for applying the logical code. In this second step we will implement the IArea interface by creating a new C# class with name AreaService.

Implementing the WCF Service Contract

Continuing with the same WCFService console application created in the previous tutorial: Defining Service contract in WCF, now let's implement the IArea interface:
1. Create a new class with name AreaService by right-clicking on the project in the solution explorer by choosing New Item from the Addmenu.
2. Next implement the IArea interface to the class:
public class AreaService : IArea
3. Implement each method defined in the IArea interace within the AreaService class:
namespace WCFService
{
    public class AreaService : IArea
    {
        public double AreaOfRectangle(double length, double width)
        {
            double area = length * width;
            Console.WriteLine("length: {0}; width: {1}", length, width);
            Console.WriteLine("Area: {0}", area);
            return area;
        }
        public double AreaOfCircle(double radius)
        {
            double area = Math.PI * radius;
            Console.WriteLine("radius: {0}", radius);
            Console.WriteLine("Area: {0}", area);
            return area;
        }
    }
}
Now we are finished with creation of service contract and its implementation steps. Continue to next tutorial: Hosting and Running a Basic WCF Service to compile and run the service code.


Responses

0 Respones to "Implementing Service Contract in WCF"


Send mail to your Friends.  

Expert Feed

 
Return to top of page Copyright © 2011 | My Code Logic Designed by Suneel Kumar