WCF Application Communicate with Console Application



All of you know WCF (Windows Communication Foundation). A WCF service can communicate with any application like Silverlight, webforms in Asp.Net, Console Application. So this article is an introduction to WCF for beginners with a simple sample Console application for communication using WCF.
So, let's see step by step how to do WCF.

Step 1: Go to Visual Studio 2010 – crete a new website; select WCF service; give it a name.

Step 2: Go to Iservice.cs and write this code:

{
   [OperationContract]
    int Add(int a, int b);

    [OperationContract]
    int Mul(int a, int b);

}

Step 3: Now go to Service .cs and write this one:

{
    public int Add(int a, int b)
    {
        return a + b;
        throw new NotImplementedException();
    }

    public int Mul(int a, int b)
    {
        return a * b;
        throw new NotImplementedException();
    }

}

Step 4: Now add a Console application; go to file on IDE; add New project; Console application.

Step 5: Go to the Console application and right-click; add a service reference; use the Discover option; click on Discover; give a namespace like SR.

Step 6: Now write this code in the program.cs:

{

   public int Add(int a, int b)
    {
        return a + b;
        throw new NotImplementedException();
    }

    public int Mul(int a, int b)
    {
        return a * b;
        throw new NotImplementedException();
    }
}

Step 7: Run the Application.
 

erver'>

Similar Articles