Web service client given WSDL

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:

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

Related questions

Leave a Comment