What is Web
Web Service is an application that is designed to interact directly with other
applications over the internet. In simple sense, Web Services are means for
interacting with objects over the Internet.
History of Web Service or How Web Service comes into existence?
As I have mention before that Web Service is nothing but means for interacting
with objects over the Internet.
Initially Object - Oriented Language comes which
allow us to interact with two object within same application.
Then comes Component Object Model (COM) which
allows interacting two objects on the same computer, but in different
Then comes Distributed Component Object Model
(DCOM) which allows interacting two objects on different computers, but within
same local network.
And finally the web services, which allows two
object to interact internet. That is it allows interacting between two objects
on different computers and even not within same local network.
Example of Web
Weather Reporting: You can use Weather Reporting web
service to display weather information in your personal website.
Stock Quote: You can display latest update of Share
market with Stock Quote on your web site.
News Headline: You can display latest news update by
using News Headline Web Service in your website.
Web Service Communication:
Web Services communicate by using standard web protocols and data
formats, such as
Advantages of Web Service
Web Service messages are formatted as XML, a standard way for communication
between two incompatible systems. And this message is sent via HTTP, so that
they can reach to any machine on the internet without being blocked by firewall.
Here is one
question arising in your mind and that is testing a Web Service? Answer is:
You can test web service without building an entire client application.
With Asp.net you can simply run the application and test the method by entering
valid input parameters. You can also use .Net Web Service Studio Tool comes from
Creating Web Service in .Net
This Web Service will take two numbers from client web page and add these on web
service page then return to client page.
Create a Web Service Application by File > New > Web Site > Asp.net Web Services
Write a method named “Add” on “Service.cs” file
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the
public class Service
return "Hello World";
//creating method Add which will accept two arguments.
public int Add(int a, int b)
return a + b;
Build Web Service and Run the Web Service for testing by pressing F5 function
key. Copy the URL string for “Add Web
Reference” in your project
Create a Web Site by File > New > Web Site > Asp.net Web Site and create UI as
per as below format
In Visual Studio 2008, Right Click on Solution Explorer and Choose "Add Web Reference".
in Visual Studio 2010, Right Click on Solution Explorer and Choose "Add Service Reference" then click on button “Advance”, then chose “Add Web
Paste copy string in “URL” box, then
click button “go”. After few second button “Add Reference” enable then click on
After adding “Add Reference”, Solution Explorer look like this…..
Write codes on button “Add” click
public partial class
_Default : System.Web.UI.Page
//creating object of service created earlier.
localhost.Service ws =
//using Add method of web service and displaying the
result in the page.
Run this web site and enter values in TextBox then click button “Add” and see
output. E.g. 1st value is “5” and 2nd value is “15”.
Output is “20”