---
title: "xfire"
author: "arpenker"
date: "2012-05-28T05:12:27Z"
tags: ["xFire"]
categories: ["企业架构"]
slug: "xfire"
draft: false
lastmod: "2012-05-28T05:12:27Z"
id: 1542390
url: "https://arpenker.iteye.com/blog/1542390"
---

在构建路径中创建 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代码 creditcard http://localhost:8080/creditcard services.test.Icreditcard services.test.creditcardImpl 修改web.xml Xml代码 XFireServlet org.codehaus.xfire.transport.http.XFireConfigurableServlet 0 XFireServlet /services/* 访问 http://localhost:8080/project/services/服务的名字？wsdl 调用 服务 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