You are on page 1of 5

Lab Session 3: Creating Web Services using .

Net Framework

What is a Web service?

A web service is nothing but a software application which runs on the web having some exposed web
methods which other applications can use over HTTP/ HTTPS protocols using technologies such as XML,
SOAP, WSDL, and UDDI. Here in this demo, we will create one such web service and we will try to use its
web methods. We will do all of this in a single web project but you can try it in different projects on the
same machines as well as different projects on different machines.

In this demo, today, we will try to create a web service project. We will also learn how to consume the
web service in our project. Basically, at the end of this project, you should be able to use the web
methods created in web service in your code. So, if you are able to achieve this, you are good with this
concept. Let's go through each step one by one and see how it happens.

Step 1

Click on File >> New >> Project as given below.

Figure 1: Creating
New Project
Once you click on Project, you will see the following pop-up window.

Figure 2: Select Asp.Net Web Application

Step 2
 
Here, choose ASP.NET Web Application (.NET Framework) and give it a name as I have given -
WebServiceProject. Click on OK.
1. Select the Empty template.
2.  It creates a solution having the following solution structure.

Step 3

Once you click on the New Item, choose


Web Service and give it a name as given
below.
 
Figure 3: Create web Services

Now, write the following code in WebService.asmx file.

Here, WebMethod HelloWorld comes by default when you create a web service. You can change its
implementation if you want. We have implemented another method which can take a list of integers as
input and will give you some of all the lists of integers given as input.
 
Now, if you run this project and point the URL to WebService.asmx, then you will get the following
result, which indicates that your web service has been created.

How to add web service reference in Project?

For adding Web reference of this service in the project, right click on the project and click "Add Service
Reference". Once you do that you will see the following popup window.
Figure 4: Add Web service into Client side

So here we have entered the path to the web service and once you click on Go you will see the service
structure like this. You can also see methods exposed by click on WebService over here. Just give it a
namespace name which you want to use. For us, we are using ServiceReference1. Click OK and it will
add service reference of this web service in your project.

We have understood using the steps above how to create a web service and how to use a web service
using the addition of web service in C# web project in visual studio. There are other ways also available
to consume this via SOAP and other web mechanisms. Do run all these steps and you should not be
getting any issues in setting all of the above things on your machine.

Exercise:
1. Run above example step by step.
2. Create Web service Method for Addition, Subtraction & Multiplication.

You might also like