As hinted in a comment to Jon's answer, my recommendation would be to use a JAX-WS implementation like JAX-WS RI (which is included in Java 6) or Apache CXF.

I'll use JAX-WS RI to illustrate my answer as it's available out of the box, on the command line (to explain the steps) but I'd recommend using an IDE with good JAX-WS support e.g. NetBeans (see the resources at the end of the answer).

1. Generate JAX-WS artifacts from the WSDL

First run wsimport to generate JAX-WS artifacts (to put it simply, the classes you'll need to invoke the web service):

wsimport -d generated -extension -keep -p com.gatewayedi.ws -XadditionalHeaders https://testservices.gatewayedi.com/PayerList/payerlist.asmx?wsdl 

About the options:

  • -d is used to specify the target directory for the generated stuff
  • -extension is used to allow extensions (the WSDL is using a non-standard SOAP 1.2 binding)
  • -keep is to keep generated .java sources (this is will ease the development)
  • -p is used to specify a package for the generated artifacts
  • -XadditionalHeaders is used to map additional WSDL headers (that are not part of the input or output contract defined in the portType operation) to method parameters (this will make invoking the service easier).

Sorry if some of the vocabulary is cryptic but, well, welcome to SOAP web services :)

2. Implement a client

Here is a simple client showing how to invoke one of the available operations using the generated classes:

import com.gatewayedi.ws.AuthSOAPHeader;
import com.gatewayedi.ws.PayerList;
import com.gatewayedi.ws.PayerListSoap;

public class Main {

    public static void main(String[] args) {
        new Main().callWebService();
    }

    private void callWebService() {
        PayerList service = new PayerList();
        PayerListSoap port = service.getPayerListSoap();

        AuthSOAPHeader authSOAPHeader = new AuthSOAPHeader();
        authSOAPHeader.setUser("test");
        authSOAPHeader.setPassword("test");

        String payerList = port.ping(authSOAPHeader);

        System.out.println(payerList);
    }

}

Below, the generated request:

<?xml version="1.0"  standalone="no"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Header>
<AuthSOAPHeader xmlns="https://ws.gatewayedi.com/">
<User>test</User>
<Password>test</Password>
</AuthSOAPHeader>
</S:Header>
<S:Body>
<Ping xmlns="https://ws.gatewayedi.com/"/>
</S:Body>
</S:Envelope>

Don't know what credentials you're supposed to pass though.

Resources

  • Developing JAX-WS Web Service Clients (start here)
  • Introducing JAX-WS 2.0 With the Java SE 6 Platform, Part 1
  • Creating a Simple Web Service and Client with JAX-WS
  • Creating a SOAP client with either Apache CXF or GlassFish Metro (Glen Mazza's blog is a great resources)

Related questions

  • Java Webservice Client (Best way)
  • What is the best java webservice framework?

EDIT: As Pascal appears to have recent experience on this, it's probably worth reading his comment:

Nowadays, I wouldn't use Axis (I actually recommend against using it). Apache CXF or JAX-WS RI (which is included in Java 6 and offers wsimport and wsgen command line commands) are IMO much better stacks and easier to use.

So, look at the Apache CXF documentation and the introduction to JAX-WS.


Original answer

Have you tried using Apache Axis? It's a while since I've done any Java web services, but that was what I used last time... You'll want to look at WSDL2Java to generate code from the WSDL.


Apart from what has been suggested above, you can also use an IDE such as Netbeans. It basically allows you to create a webservice client through wizards, without having to go through making all the configurations yourself. This video shows you how to first create a webservice and then how to create its corresponding client. Note that in the video, whoever is doing the tutorial consumes the webservice through another web application. If you want to consume the webservice through a desktop application, just do the same procedure, the only difference is that instead of a webproject, you do it on the project you are working on.