Goal

This article describes how to generate classes from wsdl file (top-down approach).It needs only the wsimport tool, which is part of the jdk.

Used technologies

Jax-ws tool wsimport (JDK 8)

1. Generate classes with wsimport

@echo off

%JAVA_HOME%\bin\wsimport -d src -keep http://localhost:8090/ws/helloworld?wsdl

2. TestClient

package com.wstutorial.ws;

public class WsimportClientTest {

	public static void main(String[] args) {
		HelloWorldImplService service = new HelloWorldImplService();
		HelloWorld port = service.getHelloWorldImplPort();
		String result = port.sayHelloWorld("Good morning");
		System.out.println(result);
	}

}

3. Output

Hello Good morning !

4. Change the endpoint

Let's suppose we want to access another stage. Just change the endpoint url you want to talk with
package com.wstutorial.ws;

import java.net.MalformedURLException;
import java.net.URL;

public class WsimportClientStageTest {

	public static void main(String[] args) throws MalformedURLException {
		URL endpointUrl = new URL("http://localhost:18090/ws/helloworld");
		HelloWorldImplService service = new HelloWorldImplService(endpointUrl);
		HelloWorld port = service.getHelloWorldImplPort();
		String result = port.sayHelloWorld("Good morning stage");
		System.out.println(result);
	}

}