The previous article describes how to build a Jax-ws WebService server with Eclipse, and now describes how to build a client
1. Create a Web project, Dynamic Web project (file->new->dynamic Web project) named "Ws-client"
2, create the WebService client (select the client created to right-click New->other->web Services->web Service Client) and enter the address of the WSDL file in the service definition , and choose a running environment in configuration, my environment is Tomcat7.0 and CXF, and then click Next and Finish.
Eclipse background starts generating files and prints logs
Loading frontend jaxws
... Loading DataBinding JAXB ...
wsdl2java-client-d E:\workspace\ws-client\.cxftmp/src-classdir E:\workspace\ws-client\build\classes-p http:// Impl.service.demo.ws/=ws.demo.service.impl-impl-validate-exsh False-dns true-dex true-wsdllocation http:// Localhost:8081/ws-server/services/addserviceimplport?wsdl-verbose-defaultvalues-fe jaxws-db JAXB-WV 1.1 http:// LOCALHOST:8081/WS-SERVER/SERVICES/ADDSERVICEIMPLPORT?WSDL
Wsdl2java-apache CXF 3.1.6
Project structure after file generation:
3. Write main function
Package main;
Import Ws.demo.service.AddService;
Import Ws.demo.service.impl.AddServiceImplService;
public class Main {public
static void Main (string[] args) {
Addserviceimplservice service = new Addserviceimplser Vice ();
AddService port = Service.getaddserviceimplport ();
int result = Port.add (3, 4);
SYSTEM.OUT.PRINTLN (result);
}
Run the program, output:
June 14, 2016 5:09:15 pm Org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean buildservicefromwsdl
Information : Creating Service {Http://impl.service.demo.ws/}addserviceimplservice from wsdl:http://localhost:8081/ws-server/ SERVICES/ADDSERVICEIMPLPORT?WSDL
7
7 is the result of the last call to the server run via WebService.