XFire

service.IUserService.java

public interface IUserService{
    String getStringTest(String msg1, String msg2);

    List<String> getStringList();

    List<User> getUsersList();

    User[] getUsersArray();

    String[] getUsersStringArray();

    User getUserById(String id);

    void addUser(User user);
}

service.IUserService.aegis.xml

<?xml version="1.0" encoding="UTF-8"?>
<mappings>
 <mapping><!-- 返回类型是String ,String[]的,参数是String类型的方法不用定义 -->
  <method name="getStringList">
   <return-type componentType="java.lang.String" />
   <!--返回类型对应集合Collection,数组中的元素的类型-->
  </method>
  <method name="getUsersList">
   <return-type componentType="com.yongjie.ws.xfire.beans.User" />
  </method>
  <method name="getUsersArray">
   <return-type componentType="com.yongjie.ws.xfire.beans.User" />
  </method>
  <method name="getUserById">
   <return-type componentType="com.yongjie.ws.xfire.beans.User" />
  </method>
 </mapping>
</mappings>

 

META-INF/xfire/services.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xfire.codehaus.org/config/1.0">
 <service>
  <name>UserService</name>
  <serviceClass>com.yongjie.ws.xfire.service.IUserService</serviceClass>
  <implementationClass>com.yongjie.ws.xfire.service.impl.UserServiceImpl</implementationClass>
  <style>wrapped</style>
  <use>literal</use>
  <scope>application</scope>
 </service>
</beans>

 

client.TestUserService.java

public class TestUserService{
    public static void main(String[] args) {
 // 创建服务实例
 Service srvcModel = new ObjectServiceFactory().create(IUserService.class);
 // 创建代理工厂实例
 XFireProxyFactory factory = new XFireProxyFactory(XFireFactory.newInstance().getXFire());
 String helloWorldURL = "http://localhost:8081/WSXFire/services/UserService";
 IUserService srvc = null;
 try{ // 获取指定位置的web服务对象
     srvc = (IUserService)factory.create(srvcModel,helloWorldURL);
 }catch(MalformedURLException e){
     e.printStackTrace();
 }

 //调用只返回String的方法.在接口名.aegis.xml中不用设置方法名
 String result = srvc.getStringTest("msg1","msg2");
 System.out.println(result);
 
 //调用返回String[]数组的方法,在接口名.aegis.xml中不用设置方法名.
 String[] userInfo_str_arr = srvc.getUsersStringArray();
 for(String aUserInfo : userInfo_str_arr){
     System.out.println(aUserInfo);
 }
 
 //调用返回List类型值的方法,需要定义,List容器中的元素类型为String
 List<String> strList = srvc.getStringList();
 for(String str : strList){
     System.out.println(str);
 }
 
 //调用返回User[]数组
 User[] user_arr = srvc.getUsersArray();
 for(User a_user : user_arr){
     System.out.print(a_user.toString());
 }
 
 //调用返回User类型值的方法.方法参数是字符串.
 User a_user = srvc.getUserById("2");
 System.out.print(a_user.toString());

 //调用参数为User的方法,没有返回值,不用配置方法
 srvc.addUser(new User("4","添加的名称","添加的备注"));

 //调用返回List类型值的方法,需要定义,List容器中的元素类型为User
 List<User> userList = srvc.getUsersList();
 for(User user : userList){
     System.out.print(user.toString());
 }
    }   
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值