Java Web Services Guide: SOAP and REST API Development (JAX-WS & JAX-RS)
🧠 What Will You Learn in This Guide?
In this guide, you will learn the basic building blocks of developing web services with Java.
You will compare SOAP (JAX-WS) and REST (JAX-RS) architectures, then develop sample “Hello World” applications for both models.
In the last section, we will also touch on Maven, Jersey and web.xml configurations.
🌐 1. What is a Web Service?
Simply put, a web service is a software component that can be accessed over a network.
Unlike web applications, it enables data exchange between applications instead of a human.
| Feature | Web Application | Web Service |
|---|---|---|
| Target User | human | Application |
| Data Format | HTML | XML/JSON |
| Protocol | HTTP / HTTPS | SOAP or REST |
| Reuse | Limited | High |
| Session Management | Stateful | Stateless |
These differences explain why web services are so important in building platform-independent integrations.
🧩 2. Web Service Types
🧱 SOAP (Simple Object Access Protocol)
- It is an industry standard protocol based on XML.
- Platform independent; It works compatible with languages such as Java, .NET, PHP.
- It is generally preferred in secure, corporate systems.
⚡ REST (Representational State Transfer)
- It is not a protocol, but an architectural approach.
- Uses HTTP methods (GET, POST, PUT, DELETE).
- Processes JSON or XML data.
- It is easy to learn and has become the standard in modern API designs.
☕ 3. Java Web Service APIs
Java provides two powerful APIs for creating both SOAP and REST services:
- JAX-WS (Java API for XML Web Services): Used to develop SOAP-based services.
- JAX-RS (Java API for RESTful Web Services): Creates services suitable for REST architecture.
Both APIs are part of the JDK and make development much easier with their annotation structure.
💬 4. “Hello World” SOAP Service with JAX-WS
The following example creates a simple SOAP service.
package com.genixnode.jaxws.service;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.xml.ws.Endpoint;
@WebService
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT)
public class TestService {
@WebMethod
public String sayHello(String msg){
return "Merhaba " + msg;
}
public static void main(String[] args){
Endpoint.publish("https://ornek.com:8888/TestWS", new TestService());
}
}
➡️ This code creates a SOAP service running at https://example.com:8888/TestWS.
Steps:
Save the file as TestService.java.
Run it and the service will be published automatically.
Test with SOAP UI or Postman.
⚙️ 5. “Hello World” REST Service with JAX-RS
JAX-RS is used to develop RESTful services. In this example, we are using the popular implementation Jersey.
pom.xml — Maven Dependencies
<dependencies>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-servlet</artifactId>
<version>1.19</version>
</dependency>
</dependencies>
web.xml — Servlet Configuration
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.genixnode.jaxrs.service</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
REST Service Class
package com.genixnode.jaxrs.service;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
@Path("/test")
public class TestService {
@GET
@Path("/selam/{isim}")
public String sayHello(@PathParam("isim") String isim){
return "Selam, hoş geldin " + isim;
}
}
➡️ If you go to https://ornek.com/uygulama/test/selam/Ali from the browser, you will receive the reply “Hi, welcome Ali”.
🧰 6. Frequently Used Web Service Concepts
WSDL (Web Service Description Language): Defines the structure of the SOAP service.
Endpoint: The access address of the service.
Resource: In REST services, data is represented by URI.
Annotation: Special footnotes that facilitate configuration in JAX-WS and JAX-RS.
❓ Frequently Asked Questions (FAQ)
- Do I need Tomcat to run a SOAP service?
No. The service can be published directly with the Endpoint.publish() method. However, for large projects, Tomcat or GlassFish is recommended.
- Why does JAX-RS require an external library?
Because JAX-RS is a specification, an implementation such as Jersey or RESTEasy is required.
- How do SOAP and REST differ in terms of performance?
SOAP uses XML and message headers are large, which makes it slower than REST. REST is lighter because it uses JSON.
- What is RESTful architecture?
It is a stateless architectural approach that defines access to resources using HTTP methods.
- How to test web services?
SOAP UI can be used for SOAP, Postman or cURL can be used for REST.
🎯 Result
In this guide, you have seen step by step how to create SOAP (JAX-WS) and REST (JAX-RS) based web services in Java. Now you can design, test and publish your own services safely on the GenixNode infrastructure.
💬 Create a virtual server (instance) on GenixNode now and take your Java APIs live!

