JAXWS学习(四)- 返回复杂对象
来源:互联网 发布:mac pro价格 编辑:程序博客网 时间:2024/05/18 11:08
这一次,主要是看一下返回复杂对象
1.返回List<String>
服务:
package com.deppon.demo.service01;import java.util.ArrayList;import java.util.List;import javax.jws.WebMethod;import javax.jws.WebService;@WebService(serviceName="ListService")public class ListService {@WebMethod()public List<String> getCitys() {List<String> citys = new ArrayList<String>();citys.add("丹东");citys.add("青岛");citys.add("上海");return citys;}}
<?xml version="1.0" encoding="UTF-8"?><endpoints xmlns='http://java.sun.com/xml/ns/jax-ws/ri/runtime' version='2.0'> <endpointname="listService"implementation="com.deppon.demo.service01.ListService"url-pattern="/listService"></endpoint></endpoints>
重新加载项目,访问http://localhost:8080/jaxws-demo/listService
然后,我们生成客户端测试一下:
进入到客户端项目根路径,输入命令
D:\WorkSpaces\WorkSpace_SSM\jaxws-client>wsimport -keep -d bin -s src http://localhost:8080/jaxws-demo/listService?wsdl
测试代码:
package com.deppon.demo.test;import java.util.List;import com.deppon.demo.service01.ListService;import com.deppon.demo.service01.ListService_Service;public class MainTest {public static void main(String[] args) {ListService service = new ListService_Service().getListServicePort();List<String> citys = service.getCitys();System.out.println("citys->" + citys);}}
2.返回List<Person>
我们先添加一个实体类
package com.deppon.demo.service01;import java.io.Serializable;public class Person implements Serializable {private static final long serialVersionUID = -889590964471376392L;private Integer id;private String name;public Person(Integer _id , String _name) {this.id = _id;this.name = _name;}public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}}
再添加一个方法:
package com.deppon.demo.service01;import java.util.ArrayList;import java.util.List;import javax.jws.WebMethod;import javax.jws.WebService;@WebService(serviceName="ListService")public class ListService {@WebMethod()public List<String> getCitys() {List<String> citys = new ArrayList<String>();citys.add("丹东");citys.add("青岛");citys.add("上海");return citys;}public List<Person> getPersons() {List<Person> persons = new ArrayList<Person>();persons.add(new Person(1 , "路飞"));persons.add(new Person(2 , "索隆"));persons.add(new Person(3 , "乔巴"));return persons;}}
重新加载项目,访问地址:http://localhost:8080/jaxws-demo/listService
我们使用命令,重新生成一下代码
D:\WorkSpaces\WorkSpace_SSM\jaxws-client>wsimport -keep -d bin -s src http://localhost:8080/jaxws-demo/listService?wsdl
package com.deppon.demo.test;import java.util.List;import com.deppon.demo.service01.ListService;import com.deppon.demo.service01.ListService_Service;import com.deppon.demo.service01.Person;public class MainTest {public static void main(String[] args) {ListService service = new ListService_Service().getListServicePort();List<String> citys = service.getCitys();System.out.println("citys->" + citys);List<Person> persons = service.getPersons();for(Person each : persons) {System.out.println("each->" + each.getId() + "," + each.getName());}}}
这里的传递的对象,应该是需要序列化的, 具体还没有深入学习,有待研究。
- JAXWS学习(四)- 返回复杂对象
- 返回复杂对象
- jni返回复杂对象
- JAXWS学习(一)- HelloWorld
- JNI返回复杂对象之一
- 操作复杂对象结构——访问者模式(四)
- 操作复杂对象结构——访问者模式(四)
- 操作复杂对象结构——访问者模式(四)
- SqlServer学习(四)【复杂语句】
- xFire开发webService返回复杂对象
- 六、传递、返回复杂类型的对象
- xFire开发webService返回复杂对象
- xFire开发webService返回复杂对象
- Axis2传递、返回复杂类型的对象
- 传递、返回复杂类型的对象
- Android中用Ksoap获取标准webservice接口返回的复杂对象Dataset学习
- JAXWS学习(二)- 根据WSDL生成客户端
- JAXWS学习(三)- wsgen和wsimport命令讲解
- UltraEdit菜单乱码问题
- POJ 3687 Labeling Balls
- 一些常用的Windows操作快捷键
- DSS Source Code Analyse (08) - EventContext::RequestEvent
- 消费应用开发难赚钱?做个企业app store吧
- JAXWS学习(四)- 返回复杂对象
- oc中消息传递机制-附:对performSelector方法的扩充
- ORACLE启动与停止的批处理
- 【fraud detection】Google AdWords & AdSense Pay Per Click Fraud Detection
- 【fraud detection】Data analysis techniques for fraud detection
- VB数据库之分页显示记录——实例04
- 河北乐亭县长:海南着力发展旅游业农业商业 当好承接消费地
- ORA-01219 问题解决办法;ora-01031:insufficient privileges问题解决办法
- OpenGL图形管线和坐标变换