Tuesday, 28 May 2013

What is Web Service? Explain Web Service.



What is Web Service?

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. The Web service consumers are able to invoke method calls on remote objects by using SOAP and HTTP (HTTP-POST, HTTP-GET) over the Web.

Web Service is:=
  • Language Independent
  • Protocol Independent
  • Platform Independent
  • It assumes stateless service architecture.
Web Service Communication
Web Services communicate by using standard web protocols and data formats, such as
  • HTTP
  • XML
  • SOAP 
  • WSDL 
  • UDDI
Standard Web Protocols:

Ø  HTTP (Hyper Text Transfer Protocol):
HTTP is the World Wide Web standard for communication over the Internet. HTTP is standardized by the World Wide Web Consortium (W3C).
Ø  XML (Extensible Markup Language):
XML  is a well known standard for storing, carrying, and exchanging data. XML is standardized by the W3C. 
Ø  SOAP (Simple Object Access Protocol):
SOAP is a remote function calls that invokes method and execute them on Remote machine and translate the object communication into XML format. In short, SOAP are way by which method calls are translate into XML format and sent via HTTP.


Ø  WSDL(Web Services Description Language):
 
WSDL (Web Services Description Language) is an XML-based language used to define web services and to describe how to access them.  WSDL is a standard by which a web service can tell clients what messages it accepts and which results it will return. WSDL contains every detail regarding using web service and Method and Properties provided by web service and URLs from which those methods can be accessed and Data Types used. WSDL is a suggestion by Ariba, IBM and Microsoft for describing services for the W3C XML Activity on XML Protocols.

Ø  UDDI(Universal Description, Discovery and Integration):
Ø  UDDI provides a XML based standard mechanism for clients to dynamically find other web services.
Ø  UDDI is a directory service where businesses can register and search for web services.
Ø  UDDI is a public registry, where one can publish and inquire about web services.
Ø  UDDI is platform independent, open framework.
Ø  UDDI can communicate via SOAP, CORBA, Java RMI Protocol. UDDI uses WSDL to describe interfaces to web services.
 UDDI has two parts:
Ø  A registry of all a web service's metadata including a pointer to the WSDL description of a service
Ø  A set of WSDL port type definitions for manipulating and searching that registry 
Example of Web Service:
  • 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.

Advantages of Web Service:

Web Service messages are formatted as XML, a standard way for communication between two incompatible system. And this message is sent via HTTP, so that they can reach to any machine on the internet without being blocked by firewall.

Monday, 27 May 2013

Design one web service which will take department number and provide the details of employee belongs to that department.

First create one table in your database(Employee.mdf) and give name Employee in project directory and store some data for our testing purpose.
 
Then create new web application in asp.net

Open visual studio ---> Select File ---> New ---> Web Site ---> select ASP.NET Web Service
--- > choose Location: HTTP ------>choose Language: Visual C# --> Browse --> Select LocalIIS ---> Create New Web Application (named "WebServiceGridView") under the "Default Web Site" ---> Open ---> OK
After this process you can check  a directory  named "WebServiceGridView" in  C:\Inetpub\wwwroot\    created.
Then create new web service application in asp.net

In Opened visual studio ---> Go Website (Menu) --->Add New Item ---> Web Service ---> Rename WebService.asmx to Service.asmx
Now open your Service.cs file in web service website under the App_Code directory to write the code to get the employee details belongs to taken department number from database.

Service.cs
By using this webservice we can get the employee details belongs to that department.
 For that first create one new web application

In Opened visual studio ---> Go Website (Menu) ---> Add New Item ---> Web Form ---> Rename Default.aspx to  GridResult.aspx.

After creation of new website right click on solution explorer and choose “Add web reference”.
After select Add Web reference option one window will open, then you enter your locally deployed web service link i.e, http://localhost/WebServiceGridView/Service.asmx 
and click Go button.
Now click on Add Reference button (Right Side) web service will add successfully.
Then check your solution explorer like this...
 
 Now open your GridResult.aspx page and design like this................. 

GridResult.aspx

Code View:
GridResult.cs: 
Now run your application and check output:
Here Entered Department no is 10, then show this..... 
 
 Suppose, Entered department number is not exist, then show appropriate message..