Click here to Skip to main content
15,886,199 members
Articles / Programming Languages / Visual Basic
Article

Calculator Sample in WCF ’ VB

Rate me:
Please Sign up or sign in to vote.
4.08/5 (4 votes)
9 Sep 2014CPOL2 min read 25.5K   4   5   2
This is a simple calculator that contains four basic mathematical functions for common calculation.

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 WCF service successfully, we will use it in Windows Application and in the same way to Web application.

So let’s start the WCF service.

Step 1

Start Visual Studio 2010 and click->File->new->Project

Image 1

Step 2

This will open a new dialog box, select->WCF->WCF service Application and give appropriate name to your service and Click on OK button.

Image 2

Step 3

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:

Image 3

Step 4

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

Image 4

Step 5

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

Image 5

Step 6

Build and run the service in the usual way as you do in other projects of Visual Studio. The following output will be displayed:

Image 6

If you reach this output stage, it means you have created service successfully. Otherwise, something is wrong in your project.

Now, if you want to see the Metadata what was exchanged by the service, then use the red rounded click to do so.

Ok, 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

Step 1

Take a simple Windows application and design the GUI as in the given figure:

Image 7

Step 2

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

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

Image 8

Step 3

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

Image 9

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 is defined in service).

Image 10

Step 4

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

Image 11

Step 5

Make your Windows project as startup project.

Image 12

Step 6

Build and run the project, and see the output.

Image 13

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.

You can use the same concept with web application. So you should try this sample in web application by yourself.

Thanks.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionMaking it Client/Server Pin
A D Rosser25-Jan-18 13:21
A D Rosser25-Jan-18 13:21 
QuestionNo difference with MSDN Pin
leiyangge9-Sep-14 15:36
leiyangge9-Sep-14 15:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.