I wanna share…

Creating  and consuming the Web service by using a Web Application

Download Link: Click Here

 These are the definitions of Webservice.

Definition 1:

A Web service is a software application, accessible on the Web through an URL that is accessed by clients using XML-based protocols, such as Simple Object Access Protocol (SOAP) sent over accepted Internet protocols, such as HTTP. Clients access a Web service application through its interfaces and bindings, which are defined using XML artifacts, such as a Web Service Definition Language (WSDL) file.

Definition 2:

Web services are typically application programming interfaces (API) or web APIs that can be accessed over a network, such as the Internet, and executed on a remote system hosting the requested services.

 Definition 3:

A web service can be defined as a service available through the World Wide Web (Internet or Intranet) that makes use of the XML as message system and is not tied to any programming language, operating systems (OS).

Some people having a doubt about where this webservice concept will come into picture.

I will tell the best example. You want to buy a Kingfisher flight ticket in online. You can book it from Kingfisher website. Likewise you can book that ticket through makemytrip.com website also. Here makemytrip.com is using the webservice of Kingfisher.

Now I will explain about my Webservice.

Here I am explaining about Webservice concept (How to create a Webservice and how to consume that webservice using a web application) in an understandable way.

These are the steps to create a Webservice and publish it.

1.      Create a New website and create a virtual directory in IIS.

2.      Add asmx file.

3.      In .cs file write your functionality.

4.      Run the Asmx file.

These are the steps to consume a Webservice

1.      Create a New website and create a virtual directory in IIS

2.      Create an aspx file and add web reference.

3.      Invoke the properties of the webservice.

4.      Run the application.

I created a new website called webparts and create a virtual directory in IIS with that same name.

Now I created the asmx application. When we create the file .cs file also create with .asmx file. .cs will store in App_Code folder. In .cs file I wrote the web service functionality Addition, Subtract, Multiplication and Hello methods.

This is code of App_Code/ FirstWebService.cs file

[WebService(Namespace = “http://localhost/webparts”)]

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

public class FirstWebService : System.Web.Services.WebService


public FirstWebService () {

//Uncomment the following line if using designed components




public int Add(int a, int b)


return a + b;



public int Sub(int a, int b)


return a – b;



public int Multiplication(int a, int b)


return a * b;



public String Hello()


return “Welcome to the Web Service”;



Now Run the FirstWebService.asmx file.

Click on Service Description.

Click on methods like Add etc…

Finally in Visual Studio command prompt run these below commands.

WSDL http://local/webparts/FirstWebService.asmx?WSDL

csc /t: library FirstWebService.cs

When we run these commands, at the next second FirstWebService.cs and FirstWebService.dll files will create like this in your C or D drive.

Now I create the new website. In this website I created an aspx file.

Add the Web Reference like this.

1. Right click on the website and click on add Web Reference. This screen will comes.

Click on the Webservices in the local machine. It will show all the webservices which are exists in your system. Click on FirstWebservice.asmx and click Add Reference.

Web Reference is added to your site. (disco, disomap, wsdl files will create under App_Referances folder)

2. Add FirstWebService.cs and FirstWebService.dll to bin folder (which are created in C or D drive).

Webservconsumer.aspx file code behind code is:

Imports System

Imports System.Data

Imports System.Configuration

Imports System.Collections

Imports System.Web

Imports System.Web.Security

Imports System.Web.UI

Imports System.Web.UI.WebControls

Imports System.Web.UI.WebControls.WebParts

Imports System.Web.UI.HtmlControls

Imports System.Web.Services

Partial Class webservconsumer

Inherits System.Web.UI.Page

Public Sub runSrviceAdd_Click(ByVal sender As [Object], ByVal e As EventArgs)

Dim mySvc As New FirstWebService()

Label1.Text = mySvc.Hello()

Label2.Text = mySvc.Add(Int32.Parse(txtNum1.Text), Int32.Parse(txtNum2.Text)).ToString()

End Sub

Protected Sub runSrviceSub_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles runSrviceSub.Click

Dim mysvcsub As New FirstWebService()

Label1.Text = mysvcsub.Hello()

Label2.Text = mysvcsub.Sub(Int32.Parse(txtNum1.Text), Int32.Parse(txtNum2.Text)).ToString()

End Sub

Protected Sub runSrviceMulti_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles runSrviceMulti.Click

Dim mysvcMulti As New FirstWebService()

Label1.Text = mysvcMulti.Hello()

Label2.Text = mysvcMulti.Multiplication(Int32.Parse(txtNum1.Text), Int32.Parse(txtNum2.Text)).ToString()

End Sub

End Class

Run the Webservconsumer.aspx file. Output  screen will be like this.


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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: