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