Table of contents
1.
Introduction
2.
JAX-WS
3.
Steps
4.
Example
4.1.
JAX-WS Server Code
4.2.
JAX-WS Client Code
5.
Output
6.
Frequently Asked Questions
6.1.
What is JAX-WS used for?
6.2.
What is SOAP on the web?
6.3.
What is the use of JAXB API?
6.4.
What does JAX-RS stand for?
6.5.
What is the difference between Jersey and JAX-RS?
7.
Conclusion
Last Updated: Mar 27, 2024
Medium

JAX-WS Example RPC Style

Author Muskan Sharma
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Hey Readers!!

Have you ever heard about JAX-WS?

It is a technology for creating XML-based web services and clients called JAX-WS, and in this article, we'll look into the Example RPC Style JAX-WS

Now let's explore more about it in this article.

JAX-WS Example RPC Style

JAX-WS

JAX-WS is a Java programming language API for building web services, especially SOAP services. One of the Java XML programming APIs is JAX-WS. It is a component of the Java SE and Java EE platforms.

Steps

  1. First, make a Web Service Endpoint Interface with all the method declarations you wish to include in the Web Service.
  2. Make a class for the Endpoint interface implementation.
  3. At last, establish an endpoint publisher that installs the web service and creates and publishes the Endpoint at the given location.

Example

Let's make four files, three for the server and 1 for the client.

  • HeyNinjas.java
  • HeyNinajsImpl.java
  • Publisher.java
  • HeyNinjasClient.java

JAX-WS Server Code

JAX-WS Server Code

 

  • HeyNinjas.java
package com.codingninjas;  
import javax.jws.WebMethod;  
import javax.jws.WebService;  
import javax.jws.soap.SOAPBinding;  
import javax.jws.soap.SOAPBinding.Style;  
//Service Endpoint Interface  
@WebService  
@SOAPBinding(style = Style.RPC)  
public interface HeyNinjas{  
    @WebMethod String getHeyNinjasAsString(String name);  
}  
You can also try this code with Online Java Compiler
Run Code

 

  • HeyNinajsImpl.java
package com.codingninjas;  
import javax.jws.WebService;  
//Service Implementation  
@WebService(endpointInterface = "com.codingninjas.HeyNinjas")  
public class HeyNinjasImpl implements HeyNinjas{  
    @Override  
    public String getHeyNinjasAsString(String name) {  
        return "Hey Ninjas JAX-WS " + name;  
    }  
}  
You can also try this code with Online Java Compiler
Run Code

 

  •  Publisher.java
package com.codingninjas;  
import javax.XML.ws.Endpoint;  
//Endpoint publisher  
public class HeyNinjasPublisher{  
    public static void main(String[] args) {  
       Endpoint.publish("http://localhost:7779/ws/hey", new HeyNinjasImpl());  
    }  
}
You can also try this code with Online Java Compiler
Run Code

JAX-WS Client Code

JAX-WS Client Code
  • HeyNinjasClient.java
package com.codingninjas;  
import java.net.URL;  
import javax.XML.namespace.QName;  
import javax.XML.ws.Service;  
public class HeyNinjasClient{  
    public static void main(String[] args) throws Exception {  
    URL URL = new URL("http://localhost:7779/ws/hey?wsdl");  
   
        //1st argument service URI, refer to WSDL document above  
    //2nd argument is service name; refer to WSDL document above  
        QName QName = new QName("http://codingninjas.com/", "HeyNinjasImplService");  
        Service service = Service.create(URL, name);  
        HeyNinjas hello = service.getPort(HeyNinjas.class);  
        System.out.println(hello.getHeyNinjasAsString("Coding Ninjas rpc"));  
     }  
 }  
You can also try this code with Online Java Compiler
Run Code

Output

Output

Frequently Asked Questions

What is JAX-WS used for?

A technology for creating XML-based web services and clients is called JAX-WS.

What is SOAP on the web?

A messaging protocol called SOAP makes it possible for the scattered components of an application to communicate.

What is the use of JAXB API?

The XML document is presented to the program in a Java format by JAXB, which makes it easier for Java programs to read XML documents.

What does JAX-RS stand for?

Java API for RESTful Web Services is referred to as JAX-RS. JAX-RS is an API and specification for the JAVA-based computer language that supports RESTful Web Services.

What is the difference between Jersey and JAX-RS?

Jersey is a JAX-RS implementation, whereas JAX-RS is a standard (basically a definition).

Conclusion

This blog has extensively discussed the JAX-WS Example RPC Style, JAX-WS Server, and JAX-WS Client Code.

We hope this blog has helped you learn about the JAX-WS Example RPC Style.

If you want to learn more, check out the excellent content on the Coding Ninjas Website:

Java Web Services 

Refer to our guided paths on the Coding Ninjas Studio platform to learn more about DSA, DBMS, Competitive Programming, Python, Java, chef infra server - users JavaScript, etc.

Refer to the links problems, top 100 SQL problems, resources, and mock tests to enhance your knowledge.

For placement preparations, visit interview experiences and interview bundles.

Thank You

Do upvote our blog to help other ninjas grow. Happy Coding!

Live masterclass