I. Introduction of TOOLS
Eclipse (Luna) + axis2-1.6.3
Second, configure Axis2 in eclipse
1. Download the latest version of Axis2
is: http://axis.apache.org/axis2/java/core/download.cgi
2. Configure Axis2 in eclipse:
Window->preferences, set up in the installation:
Where the location in the right of the map corresponds to the path address of the AXIS2 that has been downloaded to the local
Three. Create and publish WebService:
1. Create a dynamic Web project-> project name: Webserviceserver
2. Create a class in the project, the code is as follows
Package Com.hengtian.axis; Public class HelloService { public HelloService () { } public String Getmsg () { return "Hello"; }}
3. Release HelloService
1) Right click on the helloservice you want to publish, click on the following:
2) Next: Note The yellow section check publish~
3) Then keep next until the end. After the successful release, a helloservice.wsdl file will appear in the project, with the following location:
4) access to http://localhost:8080/WebServiceServer/services/HelloService?wsdl in the browser, after the successful access to the following interface, level WebService published successfully.
Four. Create a client call to the published WebService:
In eclipse, proceed as follows
1) File->new->other
2) Enter the Web Service Client, select and click Next
3) After service definition, enter the url:http://localhost:8080/webserviceserver/services/helloservice?wsdl of the previously released WebService
4) Click Next to enter:
5) Set the path, and after finish, specify the location you will see the following classes are generated:
6) Now we are looking at how to call, the code is as follows
Public classWebServiceTest { Public Static voidMain (string[] args) {method3 (); } /*** Method: Use Eclipse to automatically generate webservice calling client * based on the. wsdl file **/ Public Static voidmethod3 () {Helloserviceproxy proxy=NewHelloserviceproxy (); Proxy.setendpoint ("HTTP://LOCALHOST:8080/WEBSERVICESERVER/SERVICES/HELLOSERVICE?WSDL"); HelloService Service=Proxy.gethelloservice (); Try{String result=service.getmsg (); System.out.println (Result+ "-------------ddd"); } Catch(RemoteException e) {e.printstacktrace (); } }}
At this point, the entire process is complete.
Add:
1. Both Webserviceserver Engineering and webserviceclient need the jar package in the Axis2
There are many ways to invoke methods in WebService in 2.Java, only one is used here, and will continue to be replenished in the future.
Eclipse+axis2 creating webservice and corresponding client calls