1、
为Web工程添加Axis支持
开发手册
编撰人:董新峰
审核人:
审核日期:
保密级别:
文档版本:1.0
8
版本历史
日期
版本
说明
作者
2012-5-15
1.0
创建文件,编写文档框架
董新峰
目录
1. 为eclipse安装工具 4
2. 创建WDSL文件 4
3. 生成Client文件 4
4. 添加jar包支持 5
5. 添加WSDD文件 5
6. 配置Web.xm
2、l 6
7. 接口开发 7
8. 测试代码 8
1. 为eclipse安装工具
2. 创建WDSL文件
工程中创建WDSL文件,添加需要使用的方法:
3. 生成Client文件
右键WSDL文件:
4. 添加jar包支持
5. 添加WSDD文件
放置该文件到classpath目录,并作如下修改:
4、value="com.xxx.de.webservice.DeServices" />
6. 配置Web.xml
5、>AxisServlet
Apache-Axis Servlet
org.apache.axis.transport.http.AxisServlet
AxisServlet
/servlet/AxisServlet
6、servlet-mapping>
AxisServlet
*.jws
AxisServlet
/services/*
7. 接口开发
定义接口
package com.xx
7、x.de.webservice.de;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface DeServices_PortType extends Remote {
public String newOperation(String in) throws RemoteException;
/**
* 测试代码
* @return
* @throws RemoteException
*/
public Stri
8、ng hello() throws RemoteException;
}
实现接口:
package com.xxx.de.webservice;
import java.rmi.RemoteException;
import com.icss.de.webservice.de.DeServices_PortType;
public class DeServices implements DeServices_PortType {
public String hello() throws RemoteException {
//编写具体处理
9、逻辑
return null;
}
public String newOperation(String in) throws RemoteException {
return null;
}
}
8. 测试代码
package com.xxx.de.webservice;
import javax.xml.namespace.QName;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axi
10、s.encoding.XMLType;
public class WebServiceClientTest {
public static void main(String arg[]) {
try {
// 服务端的url,需要根据情况更改。
String endpointURL = "http://localhost:8080/de/services/DeServices";
// Web服务端点地址
Service service = new Service();
Call call = (Call) service.creat
11、eCall();
call.setTargetEndpointAddress(new .URL(endpointURL));
// 设置操作的名称
call.setOperationName(new QName("DeServices", "hello"));
// 返回的数据类型
call.setReturnType(XMLType.XSD_STRING);
// 执行调用
String ret = (String) call.invoke(new Object[] {});
System.out.println(ret);
} catch (Exception e) {
e.printStackTrace();
}
}
}