日期:2014-05-19 浏览次数:20832 次
import data.User;
public class ComplexTypeService {
public String[][] getTwoArray() {
return new String[][] { { "中国", "北京" }, { "日本", "东京" }, { "中国", "上海", "南京" } };
}
public User getUser() {
User user = new User(0, "Jack", "Beijing");
return user;
}
}
package data;
import java.io.Serializable;
public class User implements Serializable {
private static final long serialVersionUID = 1715338269623256997L;
private int id;
private String name;
private String address;
public User(int id, String name, String address) {
super();
this.id = id;
this.name = name;
this.address = address;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
package webservice;
import javax.xml.namespace.QName;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
import data.User;
public class ComplexTypeServiceClient {
public static void main(String[] args) {
RPCServiceClient rpcServClient = null;
try {
rpcServClient = new RPCServiceClient();
} catch (AxisFault e) {
e.printStackTrace();
}
Options options = rpcServClient.getOptions();
String url = "http://localhost:8080/axis2/services/ComplexTypeService";
EndpointReference endpointRef = new EndpointReference(url);
options.setTo(endpointRef);
//第一个服务
QName qname = new QName("http://ws.apache.org/axis2", "getTwoArray");
Object[] result = null;
try {
result = rpcServClient.invokeBlocking(qname, new Object[] {}, new Class[] { String[][].class });
} catch (AxisFault e) {
e.printStackTrace();
}
String[][] strss = (String[][]) result[0];
for (String[] strs : strss) {
for (String str : strs) {
System.out.print(str + '\t');
}
System.out.println();
}
//第二个服务
qname = new QName("http://ws.apache.org/axis2", "getUser");
try {
result = rpcServClient.invokeBlocking(qname, new Object[] {}, new Class[] { data.User.class });
} catch (AxisFault e) {
e.printStackTrace();
}
User user = (User)result[0];
System.out.println(user.getId());
System.out.println(user.getName());
System.out.println(user.get