使用xFire框架实现webservice

来源:互联网 发布:代理软件打不开网页 编辑:程序博客网 时间:2024/05/01 21:12

首先要引入xfire框架所需的jar包,xfire-all.jar和xalan.jar这俩个包是必须的。然后在src下建立文件夹META-INF以及子目录xfire。在此文件下建立services.xml文件。添加内容例如:

<!-- START SNIPPET: services -->
<beans xmlns="http://xfire.codehaus.org/config/1.0">
  <service>
    <name>BookService</name>
    <namespace>http://guoxinlandian.nkd.jdt/BookService</namespace>
    <serviceClass>cn.xb.biz.IProcessCreditcard</serviceClass>
    <implementationClass>cn.xb.biz.ProcessCreditCard</implementationClass>
  </service>
</beans>
<!-- END SNIPPET: services -->

以上是在服务端的部署,

然后是部署客户端,客户端同样需要加那俩个必须的包,然后是在客户端实现的主要6步,如:

//1服务模型创建
  Service serviceModel = new ObjectServiceFactory().create(IProcessCreditcard.class);
  System.out.println("返回了服务模型");
  //2XFire对象的创建
  XFire xfire = XFireFactory.newInstance().getXFire();
  //3代理工厂的创建
  XFireProxyFactory factory = new XFireProxyFactory(xfire);
  //4服务url
  String serviceUrl = "http://localhost:8080/WSS/services/BookService";
  //5接口对象
  IProcessCreditcard client = null;
  try {
   client = (IProcessCreditcard) factory.create(serviceModel, serviceUrl);
  } catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  //6服务

服务即为接受业务层的信息向服务端发送,和页面的跳转。

感受:学习了webservices

原创粉丝点击