Web Services
WEB SERVICES PROVIDE A way to run a service on the web and access its methods using standard protocols, including Simple Object Access Protocol (SOAP), Extensible Markup Language (XML), Web Service Description Language (WSDL), and Hyper Text Transfer Protocol (HTTP).
Technically a Web Service is nothing more then an application that exposes its interfaces to a client who wants to access the service's abilities.
The uses of a web services include validating credit cards, searching for data in a database, inserting an order into a shopping carts and updating a guest list.
Web Services under .NET run by invoking methods in the service directly through HTTP or SOAP, so someone wanting to run your Web Service from their computer at home can simply send an HTTP call to your service, passing the parameters in a standard Uniform Resource Locator (URL).
Three attribute to make a Web Service:
Discovery: First, we need to locate the Web Service. We locate the Web Service through the Discovery Service Protocol. The *.disco file stores the protocol in your Visual Studio (VS) .NET project. This file contains references to all the Web Services under our Web site's virtual directory. VS can automatically generate this file for you. The discovery file (.vsdisco), an XML file, is used to identify searchable paths on the web server used by discovery process.
Description: Once we have discovered our service, we need a way to tell the client what methods, classes and so on the Web Service has and what writing protocol (SOAP, HTTP etc.) the services are using. We do this through WSDL, an XML format. VS provide tools for generating WSDL files automatically from your services.
Writing Protocol: Web Services under the .NET use two main protocols. HTTP-post/ HTTP-get and SOAP. HTTP-post and HTTP-get enable you to send and receive information via a URL by passing and receiving name value pair strings. HTTP can only pass strings that represent different data types. SOAP allows you to pass a richer type of information, such as datasets.
Exploring Web Services and the .NET Framework Library
The .NET Framework class library provides four namespaces that contain Web Services classes. These namespaces are:
System.Web.Services
System.Web.Services.Description
System.Web.Services.Discovery
System.Web.Services.Protocol
System.Web.Services namespace provides classes that enable us to build and use Web Services. It has four classes. The WebService class defines the optional base class for Web Services, which provide direct access to an ASP.NET application. Server, Session, User and context are some of its properties.
WebMethodAttribute, WebServiceAttribute and WebServiceBindingAttribute are other classes of this namespace.
The System.Web.Services.Description namespace provides classes that enable you to describe a WSDL.
The System.Web.Services.Discovery namespace provides classes the enable Web service consumers to locate a Web service through discovery.
The System.Web.Services.Protocol namespace provides classes that define the protocol used to transmit data between a client and a Web service.
Creating a Web Service in VS
To understand Web Services better, I'll show you how to build a simple Web Service. The Web Service will receive an order ID and then query the Northwind database's Orders table for the correct order. It'll then return the order in a DataSet.
The first step in creating the Web Service is to select File->New->Project and choose the ASP.NET Web Service template, as shown in following figure: 
Figure 1.
This creates a Web Services project on Web server. By default, localhost is available as a Web Server on your development machine. If we look the solution explorer then we see that a list of files created automatically for the project, as shown in following figure:

Figure 2.
The web.config file is an XML file containing information on how to run the service under ASP.NET.
The service.asmx file servers as the entry point into the service. The code behind the service.cs is where we will place the method for retrieving the order. If we view the service.cs then initial code we find there: 
Figure 3.




Join the conversation! Your thoughts help the community grow.