webservice客户端应用

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;
        }

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值