How to write hello world Java Webservice client

Connect with

Hello world java web services client
In this post of hello world java web services client in java, you can write your JAX-WS hello world Java client example.

1. Overview of how to write web service client in Java

You can gerate client from WSDL Java in different way. If you have a WSDL, and it’s accessible, you can generate client from WSDL java client code on your terminal using wsimport tool. If you are interested in, how to generate java web service source code using wsimport? you can visit How to generate Java Web service artifact using wsimport (on Linux terminal or window terminal).

2. Prerequisite to create java web services client

If you don’t know JAX-WS client example, then this post is important for you. You must have installed following in your machine (laptop/desktop/server) as you can generate client from WSDL Java by using wsimport tool.

  • JDK 6 or latter version
  • IDE (Eclipse or any another)
  • javapath enrironment configured to access wsimport utility from folder
  • copy generate java webservice client artifact in your project
  • Your Hellow World java webservices up and running and ready to access

3. Wrting of java webservice client

How to write web service client in Java is very simple by using wsimport tool. You have to provide your WSDL to wsimport tool to generate client from WSDL Java.
File: HelloWorldWSClient.java

package com.mysoftkey.jaxws.client;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import com.mysoftkey.jaxws.hellowold.HelloWorldImpl;
/**
 * hello world java web services client side code to invoke web services. 
 * Generate client from WSDL java by using wsimport and WSDL file and run the following code.
 * JAX-WS client example
 * @author Ranjeet Jha
 */
public class HelloWorldWSClient {
 public static void main(String[] args) {
  try {
   URL url = new URL("http://localhost:8080/HelloWorldWS/HelloWorldWS?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://hellowold.jaxws.mysoftkey.com/", "HelloWorldImplService");

   Service service = Service.create(url, qname);

   HelloWorldImpl hello = service.getPort(HelloWorldImpl.class);
   String response = hello.sayHelloWorld("Hi mysoftkey.com");
   System.out.println(response);

  } catch (Exception e) {
   System.err.println("exception caught while running webservice , msg : " + e.getMessage());
  }

 }
}

Output of JAX-WS client example
output of JAX-WS hello world java client example.

Hello world JAX-WS, Hi mysoftkey.com

4. Reference

For JAX-WS client example , you can visit docs.Jboss.org Official website too for more details.

Thanks for visiting this page for JAX-WS hello world java client example.
Happy Learning 🙂 for gererate client from WSDL java, you can visit JAX-WS web services tutorial page.
Your comments are welcome to improve this post.


Connect with

1 thought on “How to write hello world Java Webservice client”

Leave a Comment

Your email address will not be published. Required fields are marked *