What is Web Service?
Web service is a standardized medium to propagate communication between the client and server applications on the World Wide Web. A web service is a software module that is designed to perform a certain set of tasks.
There are mainly two types of web services.
1. SOAP web services — Simple Object Access Protocol. It is an XML-based protocol for accessing web services
2. RESTful web services — REpresentational State Transfer. An architectural style not a protocol
Java Web Services API
There are two main API’s defined by Java for developing web service
1. JAX-WS — for SOAP web services
2. JAX-RS — for RESTful web services
There are two ways to develop JAX-WS example.
1. RPC style
2. Document style
JAX-RPC is a specification that defines the Java APIs for making XML-based remote procedure calls (RPC). These APIs are used to invoke and get a response from a Web service using SOAP 1.1, and XML-based protocol for exchange of information in a decentralized and distributed environment.
There are created 4 files for hello world JAX-WS example:
The first 3 files are created for server side and 1 application for client side.
JAX-WS Server Code
After running the publisher code, you can see the generated WSDL file by visiting the URL: http://localhost:7779/ws/hello?wsdl
JAX-WS Client Code
JAVA RPC concepts that we identify from Helloworld example
- The client stub is called by the client.
- The client stub makes a system call to send the message to the server and puts the parameters in the message.
- The message is sent from the client to the server by the client’s operating system.
- The message is passed to the server stub by the server operating system.
- The parameters are removed from the message by the server stub.
- Then, the server procedure is called by the server stub.