How to write hello world Java Webservice client

Connect with

Oracle Java
In java, you can write your java webservice client by different ways. If you have wsdl, and its accessible, you can generate java client code on terminal using wsimport tool. If you are interested in, how to generate java webservice source code using wsimport? you can visit our another post, i.e. How to generate Java Webservice artifact using wsimport (on linux terminal or window).

1. Prerequisite to create java web services client

You must have installed following in your machine (laptop/desktop/server)

  • 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

2. Wrting of java webservice client


package com.mysoftkey.jaxws.client;


import javax.xml.namespace.QName;

import com.mysoftkey.jaxws.hellowold.HelloWorldImpl;

 * This is client side code to invoke webservice.
 * Generate java source code by using wsdl file and run the following coe.
 * @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("", "HelloWorldImplService");

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

   HelloWorldImpl hello = service.getPort(HelloWorldImpl.class);
   String response = hello.sayHelloWorld("Hi");

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


Console Output 

Hello world JAX-WS, Hi

Your comments are welcome to improve this post. Happy Learing 🙂

Connect with

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

Leave a Reply

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