Java tutorial - Consume API WebService

These tutorials used the old deprecated directkit (legacy) due to request from our clients. We recommend directkitxml instead. See Requests and responses for more information

There is several way to consume WebService in Java. In this tutorial we will use JAX-WS (which is included in the JDK by default). You can also use other frameworks such as Spring or AXIS2..

Step 1: Generate the portable artifacts (or stubs)


Now go to  your /src folder, and run the following command

  • In this example we generated a set of *.java in the package lw.api
  • The generated artifacts can be use in any projects

  • The wsimport command can be found in the JDK. Eg: C:\Program Files\Java\jdk1.8.0_66\bin\wsimport.exe
  • In Eclipse, the source level must to be configure to Java 1.5 or newer

Step 2: Consume the webservice

package lw.api.client;
import lw.api.*;
public class Program {
	public static void main(String[] args) {
		try {
			URL endpoint = new URL("");
			ServiceMb service = new ServiceMb(endpoint);
			ServiceMbSoap soap = service.getServiceMbSoap();
			System.out.println("Call Web Service");
			String resu = soap.getWalletDetails("sc", "", "foo", "654321", "fr", "1.0", "", "ua");
			System.out.println("Return result"+resu);
		catch (Exception ex) {