Recently, a project was developed using WebService. I heard axis2 is good, so I downloaded it from Apache. Because I used it for the first time and was unfamiliar with it, I had to search for it online. Article I found that there were very few introductions on the Internet, or I had to go to the documents provided by axis2. After a few days of study, an instance is called. I will discuss it with you!
I. Environment:
1. jdk1.5 + tomcat5.5 + axis2_1.1.1
2. It seems that JDK 1.4 or above and Tomcat 4.0 or above are required.
Ii. preparations:
1. Download axis2 and download standard binary distribution and war distribution from http://ws.apache.org/axis2.
2. Decompress standard binary distribution, such as: $ axis2_home $ = D: \ axis2-1.1.1.
3. decompress war distribution to $ tomcat_home $ \ webapps \ axis2 (Note: You must manually add the axis2 folder here ), alternatively, you can use ant to create an axis2.war file, put it under $ tomcat_home $ \ webapps, and start Tomcat. Then, Tomcat will automatically create an axis2 folder under webapps.
4. Set the environment variables: Create java_home and axis2_home, add the storage addresses of your JDK and axis2, and add their bin to path. This makes it easy to generate a WSDL file.
5. You may also add these *. Jar packages under $ tomcat_home $ \ webapps \ axis2 \ WEB-INF \ Lib to the classpath of the environment variable. Of course, you may not need to use idea.
Iii. test:
1. Start Tomcat and open the browser. Enter http: // localhost: [port]/axis2/to enter the welcome page of axis2. Click "Validate". If no error is reported, it should be said that the environment has been set up !!
2. click the "Administration" initial user name and password are: Admin and axis2, of course you can also go to $ tomcat_home $ \ webapps \ axis2 \ WEB-INF \ conf \ axis2.xml by changing the user name and password.
4. A simple instance
1. The instance is a file under $ axis2_home $ \ samples \ quickstartaxiom. Here there is a service: stockquoteservice. Java, client: axiomclient. Java two java files.
2. Compile the stockquoteservice. Java file. I use intellij idea. So after compiling the class file in $ atat_home $ \ webapps \ axis2 \ WEB-INF \ Classes \ [Package]. stockquoteservice. Class, Here package I will not say much.
3. Generate the WSDL file. Here we use the built-in axis2 java2wsdl. BAT to generate the WSDL file: Enter the DOS command prompt to $ tomcat_home $ \ webapps \ axis2 \ WEB-INF \ Classes, enter:
Java2wsdl-CP.-CN [Package]. stockquoteservice-of... \ WSDL \ stockquoteservice. WSDL
-CN is the specified class, and-of is to output the file to the specified location. Here I created a WSDL folder under $ atat_home $ \ webapps \ axis2 \ WEB-INF to store the WSDL file.
4. The following can be packaged. The service package in axis2 is named after the suffix. AAR. You can use the command ant generate. Service (I have never used it ). Another method is to download the plug-in from the Internet. Because intellij is used, download the plug-in and decompress it to the installation file directory plugins. You can use the plug-in to package the package. After packaging, it should have the following structure:
Stockquoteservice. AAR
-Services. xml
-Stockquoteservice. WSDL
-Stockquoteservice. Class
Note: The package should be in the same directory as the META-INF.
5. Upload service. Two methods: 1. directly call stockquoteservice. AAR file copy to $ tomcat_home $ \ webapps \ axis2 \ WEB-INF \ Services, restart tomcat, open the browser, enter: http: // localhost: [port]/axis2/enter the management interface. Click "available services" in the left column to see that the service has been uploaded. 2. Click "upload service" on the left-side menu bar of the management interface to upload files.
6. In the browser, enter: http: // localhost: [port]/axis2/services/stockquoteservice? If the WSDL is correct, enter http: // localhost: [port]/axis2/services/stockquoteservice? XSD is correct.
It indicates that the service has been deployed.
7. perform a test. Compile axiomclient. Java into a class file and run the command. The result is: current price of WSO: 42. The service call is complete.
Note: In the axiomclient. Java file, note the Port:
Private Static endpointreference targetepr =
New endpointreference (
"Http: // localhost: [port]/axis2/services/stockquoteservice ");
As for other features, such as the transmission mechanism, you can understand it yourself.
Please kindly advise !!!!
Continue Learning -- yxxiao0929
My email: xyx-820929@163.com