1.下载apache公司的axis包.将lib拷贝到工程中
2.将axis包中的web.xml相关配置拷贝到自己的web.xml中
3.在WEB-INF下建立server-config.wsdd
如:
xmlns:handler="http://xml.apache.org/axis/wsdd/providers/handler"
xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="defaultClientConfig" xsi:type="deployment">
type="java:org.apache.axis.handlers.JWSHandler" regenerateElement="false">
type="java:org.apache.axis.handlers.JWSHandler" regenerateElement="false">
type="java:org.apache.axis.handlers.http.URLMapper" regenerateElement="false"/>
type="java:org.apache.axis.transport.local.LocalResponder" regenerateElement="false"/>
type="java:org.apache.axis.handlers.SimpleAuthenticationHandler" regenerateElement="false"/>
value="org.apache.axis.transport.http.QSListHandler" regenerateElement="false"/>
value="org.apache.axis.transport.http.QSMethodHandler" regenerateElement="false"/>
value="org.apache.axis.transport.http.QSWSDLHandler" regenerateElement="false"/>
type="java:org.apache.axis.handlers.http.HTTPAuthHandler" regenerateElement="false"/>
provider="java:RPC" style="rpc" use="encoded" validate="true">
value="com.xkk.webservice.service.example.impl.SayHello" regenerateElement="false"/>
http://impl.example.service.webservice.xkk.com
保存wsdd
然后部署到服务器中.
4.打开以下网址
http://localhost:8080/你的工程名/servlet/AxisServlet
从以下网址中获得 SayHello.wsdl文件
http://localhost:8080/testSimpleAxisService/services/SayHello?wsdl
5.新建客户端工程
将SayHello.wsdl放到工程根目录下.
执行控制台命令.生成客户端调用web程序
如:
set Axis_Lib=H:/place/WebRoot/WEB-INF/lib
set Java_Cmd=java -Djava.ext.dirs=%Axis_Lib%
set Output_Path=H:/place/testAxisCustomer/src
set Package=com.test
%Java_Cmd% org.apache.axis.wsdl.WSDL2Java -o%Output_Path% -p%Package% server-config.wsdl pause
也可以用eclispe配置参数执行控制台程序
将其放入指定包下
6.执行web客户端调用程序
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import com.xxx.webservice.guest.sayHello.SayHelloServiceLocator;
import com.xxx.webservice.guest.sayHello.SayHelloSoapBindingStub;
public class TestMain {
private static SayHelloSoapBindingStub binding;
static {
SayHelloServiceLocator bssl=new SayHelloServiceLocator();
//web服务的服务端的地址
bssl.setSayHelloEndpointAddress("http://localhost:8080/你的web工程服务端/services/SayHello");
try {
binding = (SayHelloSoapBindingStub)bssl.getSayHello();
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
binding.setTimeout(6000);
}
public String sayHello() throws RemoteException {
return binding.toSayHello("小王21212");
}
public static void main(String[] args) {
TestMain testMain = new TestMain();
try {
System.out.println(testMain.sayHello());
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}