There are a lot of tutorials on the axis online, but there are always only a few of them to search for. After a careful look at the articles, all feel not what they want, so I organized a share.
This article describes a small example of axis application, no trouble command line operation, just follow the steps to do it. The following is a detailed procedure. (Note: This example uses axis, not AXIS2)
1. Environmental Preparedness
L MyEclipse 6.5
L TOMCAT 6
L JDK 1.5
L axis (non axis2)
2. new Web project
Create a new Web project, the project name is Axistest. When the new is complete, import the axis-related jar package shown in the following illustration.
3. Add axis -related configuration information to Web.xml
<servlet> <display-name>apache-axis servlet</display-name> <servlet-name>axisservlet</ Servlet-name> <servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class> </ servlet> <servlet> <display-name>axis Admin servlet</display-name> <servlet-name> Adminservlet</servlet-name> <servlet-class>org.apache.axis.transport.http.adminservlet</ servlet-class> <load-on-startup>100</load-on-startup> </servlet> <servlet-mapping> < Servlet-name>axisservlet</servlet-name> <url-pattern>/servlet/AxisServlet</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>AxisServlet</servlet-name> < url-pattern>*.jws</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name> Axisservlet</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping> < Servlet-mapping> <servlet-name>AdminServlet</servlet-name> <url-pattern>/servlet/adminservlet</ Url-pattern> </servlet-mapping>
4. new Java classes to provide services
Under SRC, create a new COM package, under the COM package under the new HelloWorld class, HelloWorld content as follows:
Package com; public class HelloWorld {public string SayHello (String msg) {if null==msg | | ". Equals (msg)) {return" Hello! ";} else{return "Hello" + msg + "!";}} public int sayage () {return 28;}}
5. Configure SERVER-CONFIG.WSDD
Under Web-inf, create a new SERVER-CONFIG.WSDD file with the following contents:
<deployment xmlns= "http://xml.apache.org/axis/wsdd/" xmlns:java= "http://xml.apache.org/axis/wsdd/providers/ Java "> <!--processor-->
WSDD File Label Node Description:
Deployment: Indicates that this is an axis deployment profile;
One of the Web service services provided by Service:axis. The service label parameter allowedmethod is used to specify a space-delimited method name, which can be accessed only through Web service. You can also specify this value as "*" to indicate that all methods are accessible.
Provider: Service type, there are four kinds, namely rpc,document,wrapped and message. See the API documentation for org.apache.axis.providers packages;
Parameter: Used to set the various properties of axis;
Requestflow: Bureau's request handlers, call before invoking the actual service;
Transport: Defines how the server-side transports
This web service-related stuff is already configured, and the directory structure of the project is as follows
6. deploy to Tomcat test
Publish the project to Tomcat, Access http://127.0.0.1:9999/axistest/services in the browser, and if the following page appears, the Web service deployment is successful
Click on the WSDL link above to go to the page shown in the following image
Note the namespace of the red circle above, the following test QName useful.
7. Client Testing
Under COM package, create a new test class with the name Clienttest, which reads as follows:
Package com; Import java.net.MalformedURLException; Import java.rmi.RemoteException; Import Javax.xml.namespace.QName; Import javax.xml.rpc.ServiceException; Import Org.apache.axis.client.Call; Import Org.apache.axis.client.Service; /** * @author Flower non-foggy * @date 2010-12-24/public class Clienttest {public static void main (string[) args) throws Edurlexception, remoteexception {Service service = new service (); try {call call = (call) Service.createcall ()//Set address C All.settargetendpointaddress (New Java.net.URL ("http://127.0.0.1:9999/axistest/services/helloWorldService?wsdl") ); Sets the method to execute Call.setoperationname (new QName ("http://com", "SayHello")); Set the parameters to pass in, and if there are no parameters to pass in, do not write this call.addparameter ("msg", Org.apache.axis.Constants.XSD_STRING, Javax.xml.rpc.ParameterMode.IN); Sets the returned type Call.setreturntype (Org.apache.axis.Constants.XSD_STRING); String name = "Flower is not a flower mist"; execution, calling WebService string result = (string) call.invoke (new Object[]{name}); SYSTEM.OUT.PRINTLN ("The result of the return is:" +result); catch (SErviceexception e) {e.printstacktrace ();}} }
If everything works, the results are as follows:
The result of return is: Hello flower is not misty mist!
reference materials :
1. Axis's Official information