1. Use the WSDL2java tool class provided by Axis to generate code. The command is as follows:
C: \ SoftWare \ tomcat-5.0.28 \ tomcat-5.0.28 \ webapps \ AxisWebService \ WEB-INF> java-Djava. ext. dirs = lib org. apache. axis. wsdl. WSDL2Java-s http: // localhost: 8080/AxisWebService/services/HelloWorldWSDD? Wsdl-o c :\
-S is used to set the path url of the wsdl and the wsdl file on the current physical hard disk (you can save the xml file of the wsdl on the page as a try, which is also possible)
-O is the output directory of the converted file.
The above command will produce the server implementation code and the client call code. The code file is as follows:
Deploy and undeploy are wsdd files for publishing and uninstalling WebService.
HelloWorldWSDD is a server-side code interface file that inherits the Remote interface and defines the getAge and sayHello methods.
HelloWorldWSDDService is the interface for obtaining the current Service instance
HelloWorldWSDDServiceLocator implements the HelloWorldWSDDService interface, which is useful when the client calls the current WebService.
HelloWorldWSDDSoapBindingImpl current WebService Interface Implementation of HelloWorldWSDD, You need to implement your own business method
HelloWorldWSDDSoapBindingStub at the end of the Stub will know, this can complete the implementation of the client, it can be used to call the WebService Method
The following code is generated using WSDL2Java to call WebService. Note that you must use the doscommand to publish the above service through deploy. wsdd. The following is the call code:
Code
Package localhost. AxisWebService. services. HelloWorldWSDD. clientimpl;
Import java.net. MalformedURLException;
Import java.net. URL;
Import java. rmi. RemoteException;
Import javax. xml. rpc. ServiceException;
Import localhost. AxisWebService. services. HelloWorldWSDD. HelloWorldWSDDServiceLocator;
Import localhost. AxisWebService. services. HelloWorldWSDD. HelloWorldWSDDSoapBindingStub;
Public class Client {
Public static void main (String [] args) throws ServiceException, RemoteException, MalformedURLException {
String target = "http: // localhost: 8080/AxisWebService/services/HelloWorldWSDD ";
HelloWorldWSDDServiceLocator service = new HelloWorldWSDDServiceLocator ();
HelloWorldWSDDSoapBindingStub stub = new HelloWorldWSDDSoapBindingStub (new URL (target), service );
System. out. println (stub. getAge (22 ));
System. out. println (stub. getName ("Zhang San "));
}
}
It is relatively simple to use the automatically generated code to call the client, if your WebService implementation version is JAX-WS2.0, you can use MyEclipse WebService plug-in tool to help us produce code, such as: axis2 can, next time, we will introduce the usage of Axis2.x.