posts - 44,  comments - 48,  trackbacks - 0

          ClientService.java

          package com.soft.client;

          import org.apache.axis.client.Service;
          import javax.xml.rpc.ServiceException;
          import java.net.MalformedURLException;
          import org.apache.axis.client.Call;
          import org.apache.axis.encoding.ser.BeanDeserializerFactory;
          import javax.xml.namespace.QName;
          import org.apache.axis.encoding.ser.BeanSerializerFactory;
          import java.rmi.RemoteException;

          public class ClientService {
              public ClientService() {
              }
              public UserDTO getUserDTO() {
                  String endpoint = "http://localhost:8080/WebModule/services/Myservice";
                  QName qset = new QName("urn:Myservice", "UserDTO");
                  QName qmethod = new QName("urn:Myservice", "getUserDTO");
                  Class clsUserDTO = UserDTO.class;

                  UserDTO dto = new UserDTO();
                  Service service = new Service();
                  try {
                      Call call = (Call) service.createCall();
                      call.registerTypeMapping(clsUserDTO, qset,
                                               new BeanSerializerFactory(clsUserDTO, qset),
                                               new BeanDeserializerFactory(clsUserDTO,qset));
                      call.setTargetEndpointAddress(new java.net.URL(endpoint));
                      call.setOperationName(qmethod);
                      call.setReturnClass(clsUserDTO);
                      dto = (UserDTO) call.invoke(new Object[] {});
                     
                     
                  } catch (ServiceException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  } catch (MalformedURLException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  } catch (RemoteException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  }
                  return dto;
              }
              public static void main(String[] args) {
                  ClientService cs = new ClientService();
                  UserDTO user = cs.getUserDTO();
                  System.out.println(user.getPassword());
                  System.out.println(user.getUsername());
              }
          }


          UserDTO.java
          package com.soft.client;


          public class UserDTO {

                  private String username;
                  private String password;

                  public String getPassword() {
                          return password;
                  }
                  public void setPassword(String password) {
                          this.password = password;
                  }
                  public String getUsername() {
                          return username;
                  }
                  public void setUsername(String username) {
                          this.username = username;
                  }

          }

          posted on 2007-04-16 16:58 摩西 閱讀(285) 評論(0)  編輯  收藏 所屬分類: work_2007
          主站蜘蛛池模板: 敦煌市| 商城县| 花莲市| 临潭县| 虞城县| 历史| 墨竹工卡县| 安龙县| 南漳县| 洛浦县| 朝阳县| 望奎县| 遂宁市| 泽普县| 宁晋县| 宜城市| 余姚市| 新乡市| 桑植县| 东乡县| 团风县| 漳州市| 凤城市| 渭源县| 商丘市| 阳泉市| 江安县| 南汇区| 七台河市| 波密县| 新泰市| 科技| 南昌市| 和硕县| 教育| 大丰市| 颍上县| 卢氏县| 利川市| 清镇市| 杂多县|