JAX-WS is SOAP web services in the Java ecosystem (Java EE / Jakarta EE). It’s still everywhere in “serious” enterprise stacks: contracts-first WSDLs, strong typing, and integrations with systems that aren’t moving to REST anytime soon. 😄
🔸 TLDR ✅
- ▪️ JAX-WS = SOAP in Java/Jakarta EE
- ▪️ Generate clients from WSDL for strong typing
- ▪️ Use MTOM for real-world file transfers 📎
- ▪️ EJB + JAX-WS is a powerful combo for transactional enterprise services
🔸 DEVELOPING WEBSERVICES WITH JAX-WS
- ▪️ Expose a SOAP endpoint with @WebService + @WebMethod
- ▪️ Generate a strongly-typed client from the WSDL (or build one dynamically)
- ▪️ Send attachments efficiently with MTOM (no more huge base64 payloads 🧱)
Endpoint (server-side)
import jakarta.jws.WebMethod; import jakarta.jws.WebService; @WebService(serviceName = "OrderService") public class OrderEndpoint { @WebMethod public String placeOrder(String sku, int qty) { return "OK-" + sku + "-" + qty; } }
Client (generated stub style)
// Generated from WSDL (tooling depends on your stack: Metro/CXF, etc.) OrderService service = new OrderService(); OrderEndpoint port = service.getOrderEndpointPort(); String confirmation = port.placeOrder("SKU-42", 2);
🔸 SENDING ATTACHMENTS (MTOM) 📎
Without MTOM, attachments often end up as heavy base64 blobs in XML. With MTOM, the SOAP message stays lean and the binary goes as an optimized part.
Endpoint with MTOM + DataHandler
import jakarta.jws.WebService; import jakarta.xml.ws.soap.MTOM; import jakarta.activation.DataHandler; import jakarta.xml.bind.annotation.XmlMimeType; @MTOM @WebService(serviceName = "DocService") public class DocEndpoint { public String upload( String name, @XmlMimeType("application/pdf") DataHandler file ) { return "RECEIVED-" + name; } }
Client call with a PDF
import jakarta.activation.DataHandler; import jakarta.activation.FileDataSource; DataHandler dh = new DataHandler(new FileDataSource("invoice.pdf")); String result = docPort.upload("invoice.pdf", dh);
🔸 EXPOSING EJBS AS WEB SERVICES (EJB + JAX-WS) 🏛️
EJBs can be published as SOAP endpoints with the same @WebService model, while keeping EJB benefits (transactions, pooling, security, etc.).
Expose a Stateless EJB as a SOAP service
import jakarta.ejb.Stateless; import jakarta.jws.WebService; import jakarta.jws.WebMethod; @Stateless @WebService(serviceName = "CustomerService") public class CustomerServiceBean { @WebMethod public String findCustomerName(long id) { return "Customer-" + id; } }
🔸 EJB WEB SERVICE CLIENTS (CALL SOAP FROM AN EJB) 🔁
You can inject a generated service into an EJB and call it like any typed Java API.
import jakarta.ejb.Stateless; import jakarta.xml.ws.WebServiceRef; @Stateless public class BillingBean { @WebServiceRef private CustomerService service; // generated from WSDL public String bill(long customerId) { var port = service.getCustomerServicePort(); return "BILLING for " + port.findCustomerName(customerId); } }
🔸 TAKEAWAYS 🎯
- ▪️ If you need a strict contract, tooling, and interoperability: SOAP/JAX-WS still delivers
- ▪️ MTOM is the “attachment mode” you want in production
- ▪️ EJB endpoints are great when you also want transactions + container services
- ▪️ Heads-up: in modern stacks this is typically Jakarta XML Web Services (package names changed from javax.* to jakarta.*)
#Java #JakartaEE #JAXWS #SOAP #WebServices #EJB #MTOM #EnterpriseJava #BackendDevelopment #Integration
Go further with Java certification:
Java👇
Spring👇
SpringBook👇
JavaBook👇