以下逐一講述web service在axis上的部署和開(kāi)發(fā),設(shè)置classpath set CLASSPATH=.;%AXIS_HOME%\lib\axis.jar;%AXIS_HOME%\lib\axis-ant.jar;%AXIS_HOME%\lib\commons-discovery-0.2.jar;%AXIS_HOME%\lib\commons-logging-1.0.4.jar;%AXIS_HOME%\lib\jaxrpc.jar;%AXIS_HOME%\lib\saaj.jar;%AXIS_HOME%\lib\wsdl4j-1.5.1.jar;%AXIS_HOME%\lib\log4j-1.2.8.jar;E:/thirdparty/activation/activation.jar;E:/thirdparty/activation/mail.jar
二、編寫(xiě)DII(Dynamic Invocation Interface )方式web服務(wù) 1.編寫(xiě)服務(wù)端程序HelloClient public class HelloClient { public String getName(String name) { return "hello "+name; } }
1.編寫(xiě)服務(wù)端程序server,SayHello.java,編譯server.SayHello.java package server; public class SayHello { public String getName(String name) { return "hello "+name; } } 2.編寫(xiě)LogHandler.java import org.apache.axis.AxisFault; import org.apache.axis.Handler; import org.apache.axis.MessageContext; import org.apache.axis.handlers.BasicHandler;
import java.util.Date;
public class LogHandler extends BasicHandler { public void invoke(MessageContext msgContext) throws AxisFault { /** Log an access each time we get invoked. */ try { Handler serviceHandler = msgContext.getService();
Integer numAccesses = (Integer)serviceHandler.getOption("accesses"); if (numAccesses == null) numAccesses = new Integer(0);
numAccesses = new Integer(numAccesses.intValue() + 1);
Date date = new Date(); String result = date + ": service " + msgContext.getTargetService() + " accessed " + numAccesses + " time."; serviceHandler.setOption("accesses", numAccesses);