What is a Web Service?
A Web Service is a software program that uses XML to exchange information with other software via common internet protocols. Web Service is way to interact with other object via internet. It is an application that is designed to interact with other applications. Web services allow servers to expose its functionality and clients can use this functionality according to their requirements.
In plain words we can say that it is a method of communication between two devices over the internet. A web service is function that can be accessed by other programs via internet. So the target of web services is not humans rather other programs. Web Services are protocol, platform and language independent and it is based on XML so all the communication is in XML.
Web Services Technologies
Web services use following technologies.
XML (Extensible Markup Language)
It is a markup language that provides standard rules to encode data to carry via internet. It allows users to define their own tags rather than predefined tags.
SOAP (Simple Object Access Protocol)
It is based on XML and it actually the communication protocol. It provides communication mechanism between web services and applications via internet.
WSDL (Web Services Description Language)
It is also based on XML and it is used to describe and locate Web Services.
UDDI (Universal Description, Discovery and Integration)
It is actually the directory for storing information about web services and web services interfaces.
- Open Visual Studio 2010 and Select New Website form File > New
- Now Select Add New Item from Website and select Web Service
- You will see following window on your screen.
- A WebMethod HelloWorld() is already there but you can write your own web methods as I have written Multiply() web method. This method takes two integer parameters, multiplies them and returns integer value.
public int Multiply(int x, int y)
int z = x * y;
Two important things to note here are System.Web.Services namespace and [WebMethod] attribute. You must have to use System.Web.Services namespace and specify [WebMethod] attribute top of the every method you want to expose as part of the web service. You must also need to declare these methods “public”.
- Press F5 and you will see following in your browser.
- You can test the web service by clicking on “Multiply”.
- Now provide two values and click on “Invoke”.
- You will see the result like this.