Java6 WebService 使用复杂对象
2009-12-02 00:00:00 来源:WEB开发网复杂对象可表示的语义比简单对象强大很多,这里看看在Java6的WebService中如何使用复杂对象参数。
这里的参数分两类,一类是入参,一类是返回值。
复杂对象在并不像想象中那么简单,其中还有一些玄机。请看实例:
1、开发服务,统统在服务端
package lavasoft.server;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;
/**
* Java6开发的WebService服务端
*
* @author leizhimin 2009-11-16 10:24:13
*/
@WebService
public class Java6WS {
//返回一个复杂对象
public UserBean doSomething1(String username, String address, boolean flag) {
return new UserBean(username, address, flag);
}
//接收一个复杂对象
public String doSomething2(Foo foo) {
return foo.toString();
}
public static void main(String[] args) {
//发布一个WebService
Endpoint.publish("http://192.168.14.117:9999/java6ws/Java6WS", new Java6WS());
}
}
package lavasoft.server;
/**
* 用户信息
*
* @author leizhimin 2009-11-16 16:43:35
*/
public class UserBean {
private String username;
private String address;
private boolean flag;
public UserBean() {
}
public UserBean(String username, String address, boolean flag) {
this.username = username;
this.address = address;
this.flag = flag;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public boolean isFlag() {
return flag;
}
public void setFlag(boolean flag) {
this.flag = flag;
}
@Override
public String toString() {
return "UserBean{" +
"username='" + username + '\'' +
", address='" + address + '\'' +
", flag=" + flag +
'}';
}
}