webservice -XFire 服务器端环境搭建

编程技术  /  houtizong 发布于 3年前   81
1、配置XFire运行环境:
新建一个Web 工程,命名为xfire,然后在web.xml文件中添加xfire配置
<?xml version="1.0" encoding="GB2312">   <!DOCTYPE web-app       PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"       "http://java.sun.com/dtd/web-app_2_3.dtd">          <web-app>        <servlet>       <servlet-name>XFireServlet</servlet-name>       <display-name>XFire Servlet</display-name>       <servlet-class>org.codehaus.xfire.transport.http.XFireConfigurableServlet</servlet-class>     </servlet>        <servlet-mapping>       <servlet-name>XFireServlet</servlet-name>       <url-pattern>/servlet/XFireServlet/*</url-pattern>     </servlet-mapping>        <servlet-mapping>       <servlet-name>XFireServlet</servlet-name>       <url-pattern>/services/*</url-pattern>     </servlet-mapping>      </web-app>   


其中主要就是引入了XFireServlet,用以处理Web Service请求,并且负责提供Web Service的WSDL
2.开发一个webservice,创建三个类
    Person

package com.eagle.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;}}




PersonService:

package com.eagle.service;import java.util.Date;import java.util.List;import com.eagle.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();}


PersonServiceImpl
package com.eagle.service;import java.util.ArrayList;import java.util.Date;import java.util.List;import com.eagle.bean.Person;/** * TODO web服务接口实现类 date:Jan 14, 2010 time:2:29:49 PM author:wxj * email:[email protected] */public class PersonServiceImpl implements PersonService {public int getAge() {return (int) (Math.random() * 100);}public Date getBirthday() {return new Date();}public Person getPerson() {Person person = new Person();person.setId(1);person.setAge(60);person.setName("china");person.setBirthday(new Date());return person;}public List<Person> getPersons() {List<Person> persons = new ArrayList<Person>();Person person1 = new Person();person1.setId(1);person1.setAge(60);person1.setName("ls");person1.setBirthday(new Date());persons.add(person1);Person person2 = new Person();person2.setId(2);person2.setAge(50);person2.setName("bj");person2.setBirthday(new Date());persons.add(person2);Person person3 = new Person();person3.setId(3);person3.setAge(56);person3.setName("ww");person3.setBirthday(new Date());persons.add(person3);return persons;}public String sayHello(String name) {return "hello," + name + ",welcome to xfire";}}


3.创建目录:src\META-INF\xfire

4.在此目录下新建文件services.xml
文件内容:
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://xfire.codehaus.org/config/1.0">    <service>        <name>Person</name>        <serviceClass>test.services.IPerson</serviceClass>        <implementationClass>            test.services.PersonImpl        </implementationClass>    </service></beans> 

5.如果不适用Myeclipse开发直接使用Myeclipse导入Myeclipse的xfire变量即可
如果不适用的话 则要在lib下放入xfire相关的jar包,
jar包下载地址:[url]http://xfire.codehaus.org/Download [/url]

OK,webservice服务器端创建完成,部署到tomcat下后 启动tomcat

在浏览器中输入http://localhost:8080/fire/services/person?WSDl
即可看到webservice相关配置了。

上一篇已经讲述了webservice客户端开发

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!

留言需要登陆哦

技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成

网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];

      订阅博客周刊 去订阅

文章归档

文章标签

友情链接

Auther ·HouTiZong
侯体宗的博客
© 2020 zongscan.com
版权所有ICP证 : 粤ICP备20027696号
PHP交流群 也可以扫右边的二维码
侯体宗的博客