xfire
在构建路径中创建 xfire 用户库 把 网上下载的 xfire 文件中的lib 下面的jar文件 放置到 xfire 用户库里面 另外在构建路径中添加 xfire-all-xxx.jar xalan.jar
创建服务的接口
Java代码
package test;
public interface Icreditcard {
public void credit(int cardnum,Double total);
}
创建服务接口的实现类
Java代码
package test;
public class creditcardImpl implements Icreditcard {
public void credit(int cardnum, Double total) {
// TODO Auto-generated method stub
System.out.println("卡号:"+cardnum+"总共支付"+total);
}
}
在src 下面建 META-INF /xfire/service.xml service.xml 内容
Xml代码
调用 服务
Java代码
package client;
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;
import test.Icreditcard;
public class cient {
public void doservice(){
//创建服务的元数据
Service serviceModel =new ObjectServiceFactory().create(Icreditcard.class);
//创建服务的代理
XFire xfire =XFireFactory.newInstance().getXFire();
XFireProxyFactory factory =new XFireProxyFactory(xfire);
//代理的地址
String serviceURL="http://localhost:8080/services/services/creditcard";
Icreditcard client=null;
try {
client=(Icreditcard)factory.create(serviceModel,serviceURL);
//调用服务
client.credit(66666666, 100000000000.00);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
大小: 20.1 KB