分类:
2008-04-02 11:37:54
2.要导入的包
activation-1.0.2.jar
commons-codec-1.3.jar
commons-httpclient-3.0.jar
commons-logging-1.0.4.jar
jaxen-1.1-beta-8.jar
jdom-1.0.jar
log4j-1.2.x.jar
mail-1.3.3_01.jar
spring-1.2.x.jar
stax-api-1.0.jar
wsdl4j-1.5.2.jar
wstx-asl-2.9.jar
xbean-2.1.0.jar
xbean-spring-2.2.jar
xfire-all-1.0.jar
XmlSchema-1.0.jar
3.数据发布端
(1)编写发布接口
package cn.test.service;
public interface ADService {
String[][] getDatas();
}
(2)编写实现类
package cn.test.service.impl;
import cn.test.service.ADService;
public class ADServiceImpl implements ADService{
public String[][] getDatas() {
String ads[][] = new String[3][3];
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
ads[i][j] = String.valueOf(i * j);
}
}
return ads;
}
}
4.增加xfire的配置文件services.xml
在src目录中加入/src/META-INF/xfire/services.xml
cn.test.service.impl.ADServiceImpl //实现的类
5.配置web.xml
在web.xml中加入:
org.codehaus.xfire.transport.http.XFireConfigurableServlet
6.测试xfire是否部署成功
7.编写客户端
package cn.test.service;
import java.net.MalformedURLException;
import org.codehaus.xfire.XFire;
import org.codehaus.xfire.XFireFactory;
import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;
public class CallService {
public String[][] getData(){
Service serviceModel = new ObjectServiceFactory().create(ADService.class); //注意,此处用的接口是发布端的接口ADService.class
XFire xfire = XFireFactory.newInstance().getXFire();
XFireProxyFactory factory = new XFireProxyFactory(xfire);
String serviceUrl = "";
ADService client = null;
try {
client = (ADService) factory.create(serviceModel, serviceUrl); //通过类名和地址来达到类的实例
} catch (MalformedURLException e) {
System.out.println("WsClient.callWebService(): EXCEPTION: " + e.toString());
}
String[][] datas = null ;
try {
datas = client.getDatas();
} catch (Exception e){
System.out.println("WsClient.callWebService(): EXCEPTION: " + e.toString());
}
//将所有的数据逐个打印出来
int len = datas.length;
for(int i=0;i
for(int j=0;j
}
System.out.println();
}
return datas;
}
}
8.写一个JSP调用客户端
<%@ page language="java" import="java.util.*,cn.yicha.service.*" pageEncoding="utf-8"%>