It allows the POJO classes to expose itself over the HTTP protocol, so that clients in different platforms can connect with each other.
There are two types of WebServices
1. SOAP ( Simple Object Access Protocol)
2. REST
Advantages of WebService?
Webservices allows programs written on two different platforms to work with each other.
- Main component of Service Oriented Architecture
- No location boundaries
- Very easy, tools like Axis, XFire available to the job.
- No overheads like that in RMI, CORBA
What is SOAP?
SOAP (Simple Object Access Protocol), is a XML based protocol to exchange information between client and server. The XML envelope has all the information about the function call and it parameters.
SOAP has two components
1. WSDL file (WebServices Definition Lang) : Its like the definining the java interface in XML, it allows the client to understand what methods are available , parameters and return types.
With tools like Apache Axis, CXF , commands like wsdl2java can be used to convert a java class into WSDL file.
2. SOAP Envelope
It is how data is exchanged , SOAP envelope is a XML file with a SOAP header and Body, body has all the data that is passed.
How are Exception Handled in WebServices?
Propagating errors back to a client is done by throwing exceptions. A Web service method can do this in the following ways:
* Throw a SoapException
* Throw a SoapHeader Exception
* Throw a Exception specific to the problem
REST WebServices
In REST webservices, the server uses the HTTP methods to invoke calls on the client. And the client responds by performing the action and returning a pure XML file , which has the data.
* HTTP Get - Used to retrieve data from server.
e.g http://abc.com/employees
* HTTP Post - Used to put data on server