Knight of the round table

wansong

java 调用webservice--使用axis2 RPCServiceClient

http://www.ymquba.com/article.asp?id=352


private void test_findAllUsers(){
  System.out.println("------------------test_findAllUsers-------------------------------------");
  RPCServiceClient serviceClient = null;
  try {
    serviceClient = new RPCServiceClient();
          Options options = serviceClient.getOptions();
          EndpointReference targetEPR = new EndpointReference(
                        "http://localhost:8080/Axis2141Demo/services/UserService");
          options.setTo(targetEPR);         
          QName qname = new QName("http://axis2141demo.sample/xsd", "findAllUsers");

          Object[] parameters = new Object[]{};
          Class[] returnTypes = new Class[]{User.class};
          Object[] objects = serviceClient.invokeBlocking(qname, parameters, returnTypes);
          System.out.println(" objects size-->:" + objects.length);
          for(int i = 0; i < objects.length; i++) {
           if ((objects[i] != null) && (objects[i] instanceof User)) {
            User user = (User)objects[i];
            System.out.println("User Object Not null : " + user.getUserName());
           }
    }
  } catch (AxisFault e) {
   e.printStackTrace();
  }
 }
 
 
 /**
  * "List<User> findAllUsers()"
  *
  */
 private void test_findAllUsersCascadeOrder(){
  System.out.println("------------------test_findAllUsersCascadeOrder-------------------------------------");
  RPCServiceClient serviceClient = null;
  try {
    serviceClient = new RPCServiceClient();
          Options options = serviceClient.getOptions();
          EndpointReference targetEPR = new EndpointReference(
                        "http://localhost:8080/Axis2141Demo/services/UserService");
          options.setTo(targetEPR);         
          QName qname = new QName("http://axis2141demo.sample/xsd", "findAllUsersCascadeOrder");
          Object[] parameters = new Object[]{};
          Class[] returnTypes = new Class[]{User.class};
          Object[] objects = serviceClient.invokeBlocking(qname, parameters, returnTypes);
          System.out.println(" objects size-->:" + objects.length);
          for(int i = 0; i < objects.length; i++) {
           if ((objects[i] != null) && (objects[i] instanceof User)) {
            User user = (User)objects[i];
            System.out.println(" UserName : " + user.getUserName());
            List<Order> orders = user.getOrders();
            System.out.println("OrdersSize : " + orders.size());
            for (Order order : orders) {
             System.out.println(" OrderID : " + order.getOrderId() + " --> : " + order.getOrderNo());
     }
           }
    }
  } catch (AxisFault e) {
   e.printStackTrace();
  }
 }
 
 
 
 
 
 /**
  * "User findUserByUserId(Integer userId)"
  *
  */
 private void test_findUserByUserId(){
  
  System.out.println("-------------test_findUserByUserId-----------------------------------------");
  RPCServiceClient serviceClient = null;
  try {
    serviceClient = new RPCServiceClient();
          Options options = serviceClient.getOptions();
          EndpointReference targetEPR = new EndpointReference(
                        "http://localhost:8080/Axis2141Demo/services/UserService");
          options.setTo(targetEPR);
          QName qname = new QName("http://axis2141demo.sample/xsd", "findUserByUserId");
          Object[] parameters = new Object[] {new Integer(10)};
          Class[] returnTypes = new Class[]{User.class};
          Object[] objects = serviceClient.invokeBlocking(qname, parameters, returnTypes);
          System.out.println("objects size-->:" + objects.length);
          for(int i = 0; i < objects.length; i++) {
           if ((objects[i] != null) && (objects[i] instanceof User)) {
            User user = (User)objects[i];
            System.out.println(" User Object Not null : " + user.getUserName());
           }
    }
  } catch (AxisFault e) {
   e.printStackTrace();
  }

 }

posted on 2010-12-21 08:23 w@ns0ng 阅读(2653) 评论(0)  编辑  收藏 所属分类: J2EEweb service


只有注册用户登录后才能发表评论。


网站导航: