webservice -XFire 客户端调用技术
编程技术  /  houtizong 发布于 3年前   92
package com.bean;import java.io.Serializable;import java.util.Date;public class Person implements Serializable {private int id;private String name;private int age;private Date birthday;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 int getAge() {return age;}public void setAge(int age) {this.age = age;}public Date getBirthday() {return birthday;}public void setBirthday(Date birthday) {this.birthday = birthday;}public String toString() {return "id:" + id + ", name:" + name + ", age:" + age + "birthday: "+ birthday;}}
package com.service;import java.util.Date;import java.util.List;import com.bean.Person;/** * TODO web服务接口 date:Jan 14, 2010 time:2:29:49 PM author:wxj * email:[email protected] */public interface PersonService {/** * 返回一个String类型 * * @param name * @return */public String sayHello(String name);/** * 返回一个int类型 * * @return */public int getAge();/** * 返回一个Date类型 * * @return */public Date getBirthday();/** * 返回一个自定义类型 * * @return */public Person getPerson();/** * 返回一个复杂类型 * * @return */public List<Person> getPersons();}
package com;import java.net.MalformedURLException;import org.codehaus.xfire.XFire;import org.codehaus.xfire.XFireFactory;import org.codehaus.xfire.client.XFireProxyFactory;import org.codehaus.xfire.service.Service;import org.codehaus.xfire.service.binding.ObjectServiceFactory;import com.bean.Person;import com.service.PersonService;public class ClientTest {public static void main(String[] args) {//调用外部webservice返回对象类型测试fireService fireService = new ObjectServiceFactory().create(PersonService.class);XFire fire = XFireFactory.newInstance().getXFire();XFireProxyFactory fireproxy = new XFireProxyFactory(fire);PersonService client2 = null;String serviceUrl2 = "http://localhost:8080/fire/services/person";try {client2 = (PersonService) fireproxy.create(fireService, serviceUrl2);} catch (MalformedURLException e) {System.out.println("Client call webservice has exception: "+ e.toString());}int age = client2.getAge();Person person = client2.getPerson();System.out.println("Age:" + age);System.out.println("Person->\n\t" + person);}}
请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!
技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成
网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];
文章归档
文章标签
友情链接