Microsoft’s Powerful Service: WCF Walk through

Hi Everyone!!!
Today we are going to build a new WCF Service named WCF_Calculator in part 1 and in later sessions we consume this service in console application, Windows Application.

To create a new WCF Service, Start your visual studio 2010, Click on New Project–>Window gets populated..Select C# language and WCF from left most pane–>Select WCF Service Library and give name to your service(here I gave name as WCF_Calculator) as shown below:Untitled
Now Click on OK. The solution looks like as:

solution

IService1.cs and Service1.cs are auto-generated files. As we are building Service from scratch hence we delete IService1.cs and Service1.cs files in order to know the behavior of service very well. Select these two files from the solution then right click of mouse and select Delete.
Now add new item by right click solution then add interface named “ICalculator.cs” then code as shown:
Interfaace
We are very to near to pack up..have little patience please….As we have interface ready with us…
Every interface need to be implemented, so now right click your solution and a new item select class name it as “Calculator.cs”. Code the class as shown below:

Calculator
Now the very last step to fly is open App.Config file and change the interface name which was IService1 to ICalculator in endpoint tag Contract value and also change service tag attribute name=Calculator which is our class name which is implementing our interface. Here our App.Config should look as:

Appfile
Now Press F5 and your service is in the air…Microsoft Built in WCF Service Host Tool is available which runs our service shown as:
output1
To the left most pane we find our OperationContracts named Add,Sub,Mul and Div…Click on Add then supply values to arguments which is shown in below image as 234 and 432 and click Invoke Button which displays result as:
output2
similarly click each of the OperationContract and supply values and click Invoke button to retrieve result…
We are done in Creation of the Service…In next part WCF 2 we look at how to consume this Calculator service in Console and Windows Service…Thanks…Enjoy…

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s