Table of contents
1.
Introduction
2.
JAX-WS
3.
Example Document Style
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 RI?
6.2.
What is Wsimport?
6.3.
What is the Java API specification for web service using SOAP?
6.4.
What is an XSD file in SOAP?
6.5.
Which protocol is used by RESTful web services?
7.
Conclusion
Last Updated: Mar 27, 2024
Medium

JAX-WS Example Document 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 Document Style JAX-WS.

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

JAX-WS Example Document Style

Must Recommended Topic, procedure call in compiler design

JAX-WS

A method for creating web services and clients that communicate using XML is called Java API for XML Web Services (JAX-WS). Both message-oriented and Remote Procedure Call (RPC-oriented) web services can be created by programmers using JAX-WS.

Example Document Style

We can create JAX-WS examples in document style also, like one we already know RPC.

We all need to employ Style. DOCUMENT in place of Style.RPC for the @SOAPBinding annotation.

@SOAPBinding(style = Style.DOCUMENT)//It is changed from RPC to DOCUMENT 
You can also try this code with Online Java Compiler
Run Code

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.DOCUMENT)  
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 HeyNinjas=Impl());  
        }  
}  
You can also try this code with Online Java Compiler
Run Code


The publisher class will generate this error message

To fix the issue, open a command prompt and navigate to the bin directory of your current project. Then, perform the following command:

wsgen -keep -cp . com.codingninjas.HeyNinjasImpl

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, qname);  
        HeyNinajs hello = service.getPort(HeyNinjas.class);  
        System.out.println(hello.getHeyNijasAsString("Coding Ninjas document"));  
     }  
 }  
You can also try this code with Online Java Compiler
Run Code

Output

Output

Frequently Asked Questions

What is JAX-WS RI?

A Web Services framework called JAX-WS RI 2.3. 1 gives middleware developers and end users the tools and infrastructure they need to create Web Services applications.

What is Wsimport?

The JAX-WS command line utility Wsimport is used to create each web service artifact.

What is the Java API specification for web service using SOAP?

The Java API for SOAP web services is called JAX-WS.

What is an XSD file in SOAP?

The output schema is an XSD schema object that specifies how the XML components in the body of the outgoing SOAP response should be structured.

Which protocol is used by RESTful web services?

 The HTTP protocol is used by RESTful web services.

Conclusion

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

We hope this blog has helped you learn about the JAX-WS Example Document 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