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 摩西 閱讀(287) 評論(0)  編輯  收藏 所屬分類: work_2007
          主站蜘蛛池模板: 海林市| 山西省| 双辽市| 都江堰市| 湘潭县| 固安县| 佳木斯市| 石泉县| 玉龙| 遂川县| 田林县| 临夏市| 云林县| 榆树市| 平顺县| 顺义区| 康乐县| 康定县| 高安市| 商都县| 曲周县| 林西县| 桓仁| 布拖县| 大石桥市| 高雄市| 贵州省| 汶川县| 汪清县| 德庆县| 崇礼县| 长丰县| 新津县| 离岛区| 苏尼特右旗| 从江县| 苗栗县| 奎屯市| 沙湾县| 广西| 乳源|