BASIC RPC IMPLEMENTED SYSTEM IN JAVA

Creating a basic RPC hello world system using java JAX-WS

Atheesh Rathnaweera
4 min readJul 17, 2020

What is RPC?

RPC stands for Remote Procedure Call which supports procedural programming. Using RPC we can invokes methods in shared environments.
As an example we can call a function in a remote machine from our local computer using RPC. We can define RPC as a communication type in
distributed systems.

When we dig into RPC structure, we can identify it implements the client server model. And also the calls are synchronous which makes the client
wait till the server response.

Above diagram shows the client server architecture of RPC implemented system. The events which are occurred during a remote procedure call have
listed below.

  1. Client stub is called by client.
  2. Client stub prepare a call by packing parameters to the procedure call. (This process is called marshalling)
  3. Client’s local machine sends the message to the server machine.
  4. Server stub is received the sent message.
  5. Server stub unpacks the parameters from the message. (This process is called unmarshalling)
  6. Server stub calls the server procedure and returns the results to the client machine after marshalling the data.

During this client server communication, data transportation happens in XML format. Marshalling and unmarshalling is the process that converts
data into suitable format for storage or transmission.

Development

From now on we are going to implement a system which supports RPC using java. In java there are two apis which can be used to implement web services.

  1. JAX-WS
  2. JAX-RS

We have to use JAX-WS. Because it is built for use in SOAP web services. In brief RPC style is categorized as a SOAP web service. JAX-WS is an inbuilt package in jdk, therefore you don’t have to do any extra configurations.

In our system there are two applications. One is the client side application and the other one act as the server application. First you can set up a java application using any preferred IDE. But here i have used IntelliJ IDEA.

Server application

As you can see i have added maven to my project and it is not compulsory to proceed.

Project Structure

HelloWorld.java

This is the service endpoint interface.

HelloWorldImpl.java

This is the service implementation.

Publisher.java

In here we publish our service at a endpoint to allow remote invokes.

Now we have completed the server side application of our system. We can run our publisher and the service will be available at the defined endpoint.

View the WSDL file

By visiting this URL you can view the WSDL file of our service.

http://localhost:8888/rpc/helloWorld?wsdl

WSDL stands for Web Service Description Language. It is a XML document that describes the web service. This file tells about the functions that we can implement or exposed to the client. This is like the menu of a restaurant that we can see which items are available for us.

Client application

Now we have to create another simple application that access the above service and show the result. As above set up a new java application.

Project Structure

HelloWorld.java

As in the server application, service classes should be in the client application. Therefore HelloWorld.java is created inside the services folder.

HelloWorldClient.java

Now you can run the client application and view the result.

This is the message from server : HELLO WORLD

--

--