Monday 30 July 2012

Sample WCF Service


  • Open VS10 and select new project.

  • Select  WCF Service Application and  name it as SampleCalculator


  • Then solution explorer will created with following default files like IService1.cs and Service1.svc
  • Delete those files and right click on solution explorer--> Add New Item--> Select Wcf Service template and name it as Calculator.
  • Then two files created in Solution Explorer i.e. ICalculator.cs(ServiceContract) and Calculator.svc is a service file which is having inheritance from  ICalculator.cs
  • Then write the following in ICalculator.cs(ServiceContract)


  • Then go to Calculator.svc file and implement ICalculator interface as shown.




  • This will create following method definitions in  Calculator.svc file.
  • Then modify method definitions as shown.
  • Then our WCF Service is ready to run, press F5 or Run button this will lead you to the following screen.


  • Then our service ready to check how its working, all the methods we wrote in service are visible here as shown.
  • Then double click on any method which you want test. I'm going for Add() method. After double click on Add() method we will get method test screen as shown.
  • You can check service by giving values of "a" and "b" in [Request Pane] and click on invoke you will get return value in [Response Pane].
This is WCF Service. In my next post i will try to explain how to consume this Service by using a Web App.

No comments:

Post a Comment