I. preparations:
1. Install axis. Go to the official website http://ws.apache.org/axis/download the axispackage. Then, you can decompress it to any directory. This example uses axis-bin-1_4.tar.gz, decompress to E: \ axis-bin-1_4 \ axis-1_4.
2. Prepare the development environment. This example uses MyEclipse6.0, java j2ee 1.4 library, and tomcat6 for web server.
2. Create a web project:
1. Create a web project in MyEclipse named testAxis. The project directory is D: \ JavaProject \ testAxis.
2. Deploy testAxis to tomcat.
3. import axis package: Copy all jar packages under E: \ axis-bin-1_4 \ axis-1_4 \ lib \ under the axis directory to the WebRoot \ WEB-INF \ lib under the project, myelipse is automatically added to the Reference Library:
4. modify web. xml: If there are no special cases, the simplest method is to directly replace the web. xml of the testAxis project with the web. xml in the axis decompression package. For example, in this example, replace web. xml under testAxis with E: \ axis-bin-1_4 \ axis-1_4 \ webapps \ axis \ WEB-INF \ web. xml.
3. Create a webservice:
1. Create an interface for implementation in testAxis: In this example, create sayHelloToCkp. java and store it in the com. ckp package.
PackageCom. ckp;
Public InterfaceSayHelloToCkp {
PublicString sayHello ();
}
2. Generate a wsdl file for this class:
Axis has a Java2WSDL method used to generate a wsdl for the java class. Of course, you can manually execute this method by writing the command line. Here we will talk about using MyEclipse to run this method.
Right-click the sayHelloToCkp. java class file and choose Run As --> Open Run Dialog:
In the pop-up window, create a configuration at 1, and then
Main class input in the main tab:
Org. apache. axis. wsdl. Java2WSDL;
The program Arguments input in the arguments tab, as shown in figure
-O ckp. wsdl
-L "http: // localhost: 8080/testAxis/services/ckp"
-N "urn: ckp"
-P "com. ckp" "urn: ckp"
Com. ckp. sayHelloToCkp
Click Run. The ckp. wsdl file is generated under the project Directory D: \ JavaProject \ testAxis.
3. Use wsdl to generate a service class
Axis contains the WSDL2Java method (opposite to Java2WSDL), which is used to generate a java service class for the wsdl file. Of course, you can also manually execute this method by writing command lines. Here we will talk about using MyEclipse to run this method.
Same As above, right-click Run As --> Open Run Dialog. In the pop-up window, create a configuration. This time
Org. apache. axis. wsdl. WSDL2Java,
The parameter is
-T-B-v-D-s-p com. ckp. server D: \ JavaProject \ testAixs \ ckp. wsdl
For example:
After running, related service classes, build. xml, deploy. wsdd, and undesploy. wsdd will be generated under the root directory of the project. We can copy them to src in the project (pay attention to the package location ):
4. Service deployment and generation server_config.wsdd:
Start tomcat first, and then run command line cmd to reach the class and deploy in the web server. directory where wsdd is located, such as c: \ apache-tomcat-6.0.14 \ webapps \ testAxis \ WEB-INF \ classes \ com \ ckp \ server
Run the following command:
Java-Djava. ext. dirs = E: \ axis-bin-1_4 \ axis-1_4 \ lib org. apache. axis. client. AdminClient-lhttp: // localhost: 8080/testAxis/services/ckp? Wsdl deploy. wsdd
The preceding path is the lib path in the axis decompression path, followed by the wsdl address of the future service.
After the build is successful, the WEB-INF file is visible under c: \ apache-tomcat-6.0.14 \ webapps \ testAxis \ server-config.wsdd.
5. test:
Add the following code to the implementation class CkpSoapBindingImpl. java of WebService:
PackageCom. ckp. server;
Public ClassCkpSoapBindingImplImplementsCom. ckp. server. SayHellowToCkp {
PublicJava. lang. String sayHello ()ThrowsJava. rmi. RemoteException {
Return"Hello you ";
}
}
Restart tomcat and enter http: // localhost: 8080/testAxis/services for access.
4. Generate the client:
With the WSDL file, it is the same as the generated server code, but the parameters are different. It is also generated under the project root directory: for example:
Note: In this example, if you do not want to retain the original Interface Class sayHelloToCkp. java, you can put the interface class in com. ckp. server, and then overwrite it in step 3, 3rd.