Jax-ws web service rpc style example


JAX-WS stands for Java API for XML Web Services. It is a set APIs for creating web services and clients which communicates through XML format. It allows us to write message-oriented (Document-oriented) as well as Remote Procedure Call-oriented (RPC-oriented) web services.

JAX-WS RCP style:

JAX-RPC stands for Java API for XML-based RPC. It allows a Java application to invoke a Java-based Web service with a known description while still being consistent with its WSDL description. JAX-RPC is one of the Java XML programming APIs.

A RPC style SOAP messages body contains an XML representation of the method’s call. It use the method name and its parameters to construct an XML tree which represents the method’s call stack.


First create a Web Service Endpoint Interface which will contains the declarations of all the methods we want to include in the Web Service. Create a class which provides the implementation of Endpoint interface. Finally create an Endpoint publisher which deploys the web service and creates and publishes the endpoint at the specified address.
Note: We have to run our Endpoint publisher to make Web Service available to clients. JAX-WS API is inbuilt in JDK.

Web Service:


import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
 * Service Endpoint Interface
 * @author javawithease
@SOAPBinding(style = Style.RPC)
public interface IHelloWorld {
	@WebMethod String sayHello(String name);


import javax.jws.WebService;
 * Service Endpoint Implementation
 * @author javawithease
@WebService(endpointInterface = "com.javawithease.business.IHelloWorld")
public class HelloWorld implements IHelloWorld {
	public String sayHello(String name) {
		return "JAX-WS RCP Style. Hello " + name;


import javax.xml.ws.Endpoint;
public class HelloWorldPublisher {
	public static void main(String args[]){
				new HelloWorld());

Download this example.

Web Service Client:


import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
public class HelloWorldWSClient {
 public static void main(String args[]){
  try {
	URL url = new URL("http://localhost:8080/ws/helloWorldRCP?wsdl");
	QName qname = new QName("http://business.javawithease.com/",
	Service service = Service.create(url, qname);
	IHelloWorld helloWorld = service.getPort(IHelloWorld.class);  
  } catch (MalformedURLException e) {

Download this example.

How it works:

First, client send a wsdl request to service endpoint (http://localhost:8080/ws/helloWorldRCP?wsdl) and server send the following response.

 Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.1 in JDK 6. 
 Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.1 in JDK 6. 
<definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://business.javawithease.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://business.javawithease.com/"name="HelloWorldService">
<message name="sayHello">
<part name="arg0" type="xsd:string"/>
<message name="sayHelloResponse">
<part name="return" type="xsd:string"/>
<portType name="IHelloWorld">
<operation name="sayHello" parameterOrder="arg0">
<input message="tns:sayHello"/>
<output message="tns:sayHelloResponse"/>
<binding name="HelloWorldPortBinding" type="tns:IHelloWorld">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/>
<operation name="sayHello">
<soap:operation soapAction=""/>
<soap:body use="literal" namespace="http://business.javawithease.com/"/>
<soap:body use="literal" namespace="http://business.javawithease.com/"/>
<service name="HelloWorldService">
<port name="HelloWorldPort" binding="tns:HelloWorldPortBinding">
<soap:address location="http://localhost:8080/ws/helloWorldRCP"/>

A second call, client put method invoke request in SOAP envelope and send it to service endpoint. At the service endpoint, call the requested method and put the result in a SOAP envelope and send it back to client.

Hello tutorialspointexamples

Comments are closed.