articles

Home / DeveloperSection / Articles / Calculator Sample in WCF using VB.Net

Calculator Sample in WCF using VB.Net

Calculator Sample in WCF using VB.Net

Sunil Bhagwat29726 09-Sep-2014

Introduction:

This is a simple calculator that contains four basic mathematical functions for common calculation. We will create a simple [service contract], which in turn contains four [operation Contract] of each calculator function.  After completing the WCF service successfully we will use it in Windows Application and in the same way to a Web application.
So let’s start the WCF service.

Step 1: Start Visual Studio 2010 and click->File->new->Project

Calculator Sample in WCF using VB.Net

Step 2: This will open a new dialog box select->WCF->WCF service Application and give an appropriate name to your service and click on the OK button.

Calculator Sample in WCF using VB.Net

 Step3: Now you have opened the solution explorer click on IService1.vb and delete all the code, what it contains by default. And write your own code as given below 

Calculator Sample in WCF using VB.Net

 Step4: Write down the code for contracted methods and interface Implements in the Service1.svc service class

Calculator Sample in WCF using VB.Net

Step 6: Configure the endpoint of this service in the web.config file as.

Calculator Sample in WCF using VB.Net

 Step 7: Build and run the service as in the usual way as you do in other projects of visual studio. The following output will be display. 

Calculator Sample in WCF using VB.Net

 In case you reach this output stage, it means you have created service successfully.

Otherwise, something is wrong with your project.

Now if you want to see the Metadata what was exchange by the service, the use

red rounded click to do so.

 Okay now we assume you have created the service successfully, so the next step is

how to use the service that was created.

Communicating with WCF using WINDOWS Application

 Step1: Take a simple window application and design the GUI as in given figure.

Calculator Sample in WCF using VB.Net

 Step:2: Add the service references in your project that was created by you above.

To do this click on the project menu and click on  Add Service Reference.

Calculator Sample in WCF using VB.Net

 Step3: Now you have opened a new dialog box, enter the service address or click discover the button to locate the service and click on the OK button.

Calculator Sample in WCF using VB.Net

 Now you can see the service references are added in your solution explorer, now

you can use all the service contracts under this service referenced and (depends on

what endpoint defined in service)

Calculator Sample in WCF using VB.Net

 Step4: Write down the following code in your program for consuming the service provided by the WCF.

Calculator Sample in WCF using VB.Net

 Step5: Make your windows project as the startUp project. 

Calculator Sample in WCF using VB.Net

Step6: Build and run the project, and see the output.

Calculator Sample in WCF using VB.Net

 You run and test your application for all 4 functions. I hope you learn the basic

programming with WCF and, how to use it in any application.

The same concept you can use to with web Application. So you should to try this

sample in web Application by yourself.

Thanks.


Updated 03-Jan-2020
working with Indian insurance co.

Leave Comment

Comments

Liked By