服务端:
1
2
3 import javax.jws.WebMethod;
4 import javax.jws.WebService;
5 import javax.jws.soap.SOAPBinding;
6
7 @WebService(targetNamespace = "http://jdk.study.hermit.org/testobject")
8 @SOAPBinding(style = SOAPBinding.Style.RPC)
9 public class GetObject {
10 @WebMethod
11 public UserInfo getUserInfo(String name) {
12 UserInfo user = new UserInfo();
13 user.setId(1);
14 user.setName(name);
15 return user;
16 }
17
18 }
UserInfo.java
1 public class UserInfo {
2 private int id;
3
4 private String name;
5
6 public int getId() {
7 return id;
8 }
9
10 public void setId(int id) {
11 this.id = id;
12 }
13
14 public String getName() {
15 return name;
16 }
17
18 public void setName(String name) {
19 this.name = name;
20 }
21 }
22
起动服务器
客户端测试:
1 package test;
2
3 import static org.junit.Assert.*;
4 import org.hermit.study.jdk.testobject.GetObject;
5 import org.hermit.study.jdk.testobject.GetObjectService;
6 import org.hermit.study.jdk.testobject.UserInfo;
7 import org.junit.Test;
8
9 public class TestObject {
10 @Test
11 public void getObject() {
12 GetObjectService service = new GetObjectService();
13 GetObject obj = service.getGetObjectPort();
14 UserInfo user = obj.getUserInfo("hermit");
15 assertNotNull(user.getId());
16 assertEquals("hermit", user.getName());
17 }
18 }
OK通过
posted on 2007-01-19 09:52
交口称赞 阅读(1573)
评论(1) 编辑 收藏 所属分类:
Java6