This example explains how to implement a Soap Web Service Client using Apache CXF.
Before running this application, please make sure a Soap Web Service is running in your machine and wsdl is available at
Following Client application is used with the help of generated src using the above pom . Once everything is set up in eclipse you can see the generated src in target folder. Or you can run a maven build
package com.smoothexample.pro;
/**
* Please modify this class to meet your needs
* This class is not complete
*/
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import com.smoothexample.cxf.soap.ws.AddressSoapService;
import com.smoothexample.cxf.soap.ws.impl.AddressSoapServiceImplService;
public final class AddressSoapServiceClient {
private static final QName SERVICE_NAME = new QName("http://impl.ws.soap.cxf.smoothexample.com/", "AddressSoapServiceImplService");
private AddressSoapServiceClient() {
}
public static void main(String args[]) throws java.lang.Exception {
URL wsdlURL = AddressSoapServiceImplService.WSDL_LOCATION;
if (args.length > 0 && args[0] != null && !"".equals(args[0])) {
File wsdlFile = new File(args[0]);
try {
if (wsdlFile.exists()) {
wsdlURL = wsdlFile.toURI().toURL();
} else {
wsdlURL = new URL(args[0]);
}
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
AddressSoapServiceImplService ss = new AddressSoapServiceImplService(wsdlURL, SERVICE_NAME);
AddressSoapService port = ss.getAddressSoapServiceImplPort();
{
System.out.println("Invoking getAddress...");
try {
com.smoothexample.cxf.soap.ws.Address address = port.getAddress();
System.out.println("getAddress.result=" + address.getCountry());
} catch (Exception e) {
System.out.println("Expected exception: Exception has occurred.");
System.out.println(e.toString());
}
}
System.exit(0);
}
}
Generated WSDL
This wsdl is just for your reference, location of theWSDL is defined in