Learn one of axis and Web Service

Source: Internet
Author: User

Learn one of axis and Web Service
Because Web service is needed in work, You can Google it on the internet that day to see how to make your first web service. First of all, I will not talk much about the principles of Web Services, but it is not as good as others. Besides, they are all copied from others. Let's make it happen on the whole. Create your own web service program immediately.

1. First download and install the software:
1. axis-src-1_2_1, (go download, address forgot)
2.jakarta-tomcat-5.0.18.exe (this version is installed and can be copied from other places)
At least two packages are required.

Ii. Installation
Install it on your own. It's quite simple. You 'd better change the tomcat installation name, for example, tomcat.

III.
1. Unzip the axis-src-1_2_1 package and copy everything in axis under the axis-1_2_1/webapps to the webapps of Tomcat you just created. The directory structure is as follows:
Tomcat-webapps-Axis
Then check whether the *. jar file under the Lib of your axis WEB-INF is full, there should be 8
Axis. Jar
Axis-ant.jar
Commons-discovery-0.2.jar
Commons-logging-1.0.4.jar
Jaxrpc. Jar
Log4j-1.2.8.jar
SAAJ. Jar
Wsdl4j-1.5.1.jar
(Always look at the file name of each file. The classpath will be configured later)

2. Then go to the axis-1_2_1 directory, find the Lib folder, copy the activation. jar file
Tomcat/webapps/axis/WEB-INF/lib, and the above 8 jar files together, it is OK.

4. Configure classpath
My computer-right-click Properties-advanced-Environment Variables
1. Create a variable: axis_home = D:/tomcat/webapps/axis (your own actual Tomcat directory)
2. Create variable: axis_lib = % axis_home %/WEB-INF/lib
Create these two Environment Variables
3. classpath (I believe there must be a value in this variable, which was configured during tomcat installation)

.; % Java_home %/lib/dt. jar;
% Java_home %/lib/tools. jar;
% Tomcat_home %/LIB; (the above three are installed with Tomcat configuration, and the following is axis)
% Axis_lib %/axis. jar;
% Axis_lib %/commons-discovery-0.2.jar;
% Axis_lib %/commons-logging-1.0.4.jar;
% Axis_lib %/jaxrpc. jar;
% Axis_lib %/SAAJ. jar;
% Axis_lib %/log4j-1.2.8.jar;
% Axis_lib %/wsdl4j-1.5.1.jar;
% Axis_lib %/activation. jar;
% Axis_lib %/mail. Jar
Copy it to classpath and click OK.

5. Test
This step is very important. I think, because if you don't know whether the classpath is fully configured, you should test it. Some articles will go down without testing, but there will be problems, I encountered a problem because the jar package was not imported. The error message is as follows:
Exception in thread "Main" Java. Lang. noclassdeffounderror:

Javax/WSDL/operationtype
At org. Apache. axis. description. operationdesc. <clinit> (operationdesc. Java
: 58)
At org. Apache. axis. Client. Call. addparameter (call. Java: 948)
At org. Apache. axis. Client. Call. addparameter (call. Java: 983)
At bankclient. Main (bankclient. Java: 29)
This is the error caused by no import.
In fact, you can read classpath first to avoid errors.
Click "start"-"run"-"cmd"-"Open the command line window"-"set classpath". The configured classpath is displayed completely. You can check it carefully.

6. debug axis
Start Tomcat and enter the URL http: // localhost: 8080/axis. "Hello!" appears! Welcome to Apache-axis. "Welcome word, click the validate link to verify that the. jar package required by axis is complete (needed components ).

7. Develop a web service server program
(The code is post. Thank you !)
In my example, the Web Service is used to return the value of a request field.

Import java. util .*;
 
Public class wstestservice
{
String strname = "Ryun ";
Int intage = 21;
List items = new arraylist ();

Public String getname (){
Return strname;
}

Public int getage (){
Return intage;
}

Public list getitems (){
Return items;
}
} Name the file wstestservice. JWS and save it
D:/tomcat/webapp/axis/
Access http: // localhost: 8080/axis/wstestservice. JWS. "There is a Web

Service here "indicates that the Web Service server program has been installed.
Develop a web service client program
Create the client program wstestclient. Java
The following is the client source program used to submit service requests to the Web Service Server:

Import org. Apache. axis. Client. call;
Import org. Apache. axis. Client. Service;
 
Public class wstestclient {
Public static void main (string ARGs []) {
System. Out. println ("start invoking ...");
Try {
String struri =

"Http: // localhost: 8080/axis/wstestservice. JWS ";
Service = new service ();
Call call = (call)
Service. createcall ();
Call. settargetendpointaddress (New

Java.net. URL (struri ));
Call. setoperationname ("getname ");
String ret = "" + call. Invoke (new object [] {});
System. Out. println ("I am" + RET + ".");
}
Catch (exception e ){
System. Err. println (E. tostring ());
}
System. Out. println ("finished the invoking .");
}
}
Compile and run the program. If any problem occurs, it may be caused by the Environment Variable path and classpath configuration. Check the problem by yourself.

I will not describe it here.
C:/> Cd/
C:/> javac wstestclient. Java
 
C:/> JAVA wstestclient
Start invoking...
I am Ryun.
Finished the invoking.
Complete, learn again, and summarize later

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.