reference:
http://www.cnblogs.com/cy163/archive/2008/11/28/1343516.html
pre-condition:
1.install eclipse
2.install tomcat plugin
process:
1.download axis lib: http://ws.apache.org/axis
2. set classpath:
1.AXIS_HOME
D:\Java\axis-1_4(这是我的Axis路径)
2.AXIS_LIB
%AXIS_HOME%\lib
3.AXIS_CLASSPATH
%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%\xml-apis.jar;%AXIS_LIB%\xercesImpl.jar;%AXIS_LIB%\wsdl4j-1.5.1.jar;%AXIS_LIB%\activation.jar;%AXIS_LIB%\xmlrpc-2.0.jar
4.CLASSPATH
.;%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\dt.jar; %AXIS_CLASSPATH%;
5.在你的%TOMCAT_HOME%\common\lib下需要加入三个包 activation.jar、mail.jar、tools.jar,注意这三个包是必须的,尽管tools.jar很常见,但这也是运行Axis所必须的包。
3.FIle - new - dynamic web project
projectname: oopsaxis1
target runtime: apache tomcat V5.5
4. oopsaxis1/WebContent/WEB-INF/lib,add lib from %AXIS_HOME%\lib
axis.jar/axis-ant.jar/commons-log.jar...
5.oopsaxis1/WebContent/WEB-INF/web.xml, replace by %AXIS_HOME%\webapps\axis\WEB-INF\web.xml
6.oopsaxis1/src, add java file:
public class myService
{
public String getusername(String name)
{
return "Hello " + name + ",this is an Axis DII Web Service";
}
}
7.copy myService to oopsaxis1/WebContent, and rename to myService.jws
8. right click myService.jws, run as - run on server, you can see:
http://localhost:8080/oopsaxis1/myService.jws
There is a Web Service here
Click to see the WSDL
click the link, you can see the wsdl
9. in eclipse - package explorer - src, new class:
package com.oopsaxis;
import java.net.MalformedURLException;
import java.rmi.RemoteException;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
public class myServiceTestorByjws
{
public static void main(String[] args) throws ServiceException,
MalformedURLException, RemoteException
{
String endpoint = http://localhost:8080/oopsaxis1/myService.jws;
String name = " pixysoft";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.addParameter("param1", XMLType.XSD_STRING, ParameterMode.IN);
call.setOperationName("getusername");
call.setReturnType(XMLType.XSD_STRING);
String ret = (String) call.invoke(new Object[] { name });
System.out.println("返回结果:" + ret);
}
}
10. right click myServiceTestorByjws, run as java application,you get:
返回结果:Hello pixysoft,this is an Axis DII Web Service
done!
posted on 2008-12-17 13:40
张辰 阅读(258)
评论(0) 编辑 收藏