athrunwang

纪元
数据加载中……
简单的基于xfire框架发布webserivce服务
前段时间在弄各种框架下的webservice,要弄demo,网上搜罗了许多,都讲得很好,但感觉就是说得很多很复杂,我就想弄个服务出来供我用一下, 要像网上那么做觉着太麻烦,后来参考各路神仙大佬们后,把代码极度缩小,写了个小实例供自个跑着玩,顺便代码贴上,供大伙口水
支持包:xfire框架lib下核心包,自己官网上下去,在这里就不贴了,除此之外有java环境1.6+就Ok了,其它略过,上代码了。
package com.tyky.test.bean;

public class Employee{
    
    private String id;
    
    private String name;
    
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    private String address;
    
    
}
package com.tyky.service;

import com.tyky.test.bean.Employee;

public interface EmployeeService {

    public boolean addEmployee(Employee e);
    
    public boolean deleteEmployee(String id);
    
    public Employee getEmployee(String id);
    
}
package com.tyky.serviceImpl;

import com.tyky.service.EmployeeService;
import com.tyky.test.bean.Employee;

public class EmployeeServiceImpl implements EmployeeService {

    @Override
    public boolean addEmployee(Employee e) {
        //业务想咋整自已实现去吧,我这里作例子,就直接回true了,呵呵
        return false;
    }

    @Override
    public boolean deleteEmployee(String id) {
        //业务想咋整自已实现去吧,我这里作例子,就直接回true了,呵呵
        return false;
    }

    @Override
    public Employee getEmployee(String id) {
        //业务想咋整自已实现去吧,我这里作例子,就直接回true了,呵呵
        Employee e = new Employee();
        e.setAddress("//业务想咋整自已实现去吧,我这里作例子,就直接回true了,呵呵");
        e.setId("//业务想咋整自已实现去吧,我这里作例子,就直接回true了,呵呵");
        e.setName("//业务想咋整自已实现去吧,我这里作例子,就直接回true了,呵呵");
        return e;
    }

    
}
//现在src下建个xfire文件夹,新建个service.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xfire.codehaus.org/config/1.0">

    <service>
        <name>EmployeeService</name>
        <serviceClass>com.tyky.service.EmployeeService</serviceClass>
        <implementationClass>
            com.tyky.serviceImpl.EmployeeServiceImpl
        </implementationClass>
        <style>document</style>
    </service>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
  <servlet>
    <servlet-name>XFireServlet</servlet-name>
    <servlet-class>org.codehaus.xfire.transport.http.XFireConfigurableServlet</servlet-class>
    <load-on-startup>0</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>XFireServlet</servlet-name>
    <url-pattern>/services/*</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>
//现在工程完成,可以把容器集成到eclipse里跑,也可以打war包再跑,随便你选择一个跑开即行了,访问http://localhost:8080/employeeServiceForXfire/services/EmployeeService?wsdl
<?xml version="1.0" encoding="UTF-8" ?>
- <wsdl:definitions targetNamespace="http://service.tyky.com" xmlns:ns1="http://bean.test.tyky.com" xmlns:soapenc12="http://www.w3.org/2003/05/soap-encoding" xmlns:tns="http://service.tyky.com" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc11="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
- <wsdl:types>
- <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://service.tyky.com">
  <xsd:element name="getEmployeein0" type="xsd:string" />
  <xsd:element name="getEmployeeout" type="ns1:Employee" />
  <xsd:element name="addEmployeein0" type="ns1:Employee" />
  <xsd:element name="addEmployeeout" type="xsd:boolean" />
  <xsd:element name="deleteEmployeein0" type="xsd:string" />
  <xsd:element name="deleteEmployeeout" type="xsd:boolean" />
  </xsd:schema>
- <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://bean.test.tyky.com">
- <xsd:complexType name="Employee">
- <xsd:sequence>
  <xsd:element minOccurs="0" name="address" nillable="true" type="xsd:string" />
  <xsd:element minOccurs="0" name="id" nillable="true" type="xsd:string" />
  <xsd:element minOccurs="0" name="name" nillable="true" type="xsd:string" />
  </xsd:sequence>
  </xsd:complexType>
  </xsd:schema>
  </wsdl:types>
- <wsdl:message name="getEmployeeResponse">
  <wsdl:part name="getEmployeeout" element="tns:getEmployeeout" />
  </wsdl:message>
- <wsdl:message name="deleteEmployeeRequest">
  <wsdl:part name="deleteEmployeein0" element="tns:deleteEmployeein0" />
  </wsdl:message>
- <wsdl:message name="addEmployeeResponse">
  <wsdl:part name="addEmployeeout" element="tns:addEmployeeout" />
  </wsdl:message>
- <wsdl:message name="getEmployeeRequest">
  <wsdl:part name="getEmployeein0" element="tns:getEmployeein0" />
  </wsdl:message>
- <wsdl:message name="addEmployeeRequest">
  <wsdl:part name="addEmployeein0" element="tns:addEmployeein0" />
  </wsdl:message>
- <wsdl:message name="deleteEmployeeResponse">
  <wsdl:part name="deleteEmployeeout" element="tns:deleteEmployeeout" />
  </wsdl:message>
- <wsdl:portType name="EmployeeServicePortType">
- <wsdl:operation name="getEmployee">
  <wsdl:input name="getEmployeeRequest" message="tns:getEmployeeRequest" />
  <wsdl:output name="getEmployeeResponse" message="tns:getEmployeeResponse" />
  </wsdl:operation>
- <wsdl:operation name="addEmployee">
  <wsdl:input name="addEmployeeRequest" message="tns:addEmployeeRequest" />
  <wsdl:output name="addEmployeeResponse" message="tns:addEmployeeResponse" />
  </wsdl:operation>
- <wsdl:operation name="deleteEmployee">
  <wsdl:input name="deleteEmployeeRequest" message="tns:deleteEmployeeRequest" />
  <wsdl:output name="deleteEmployeeResponse" message="tns:deleteEmployeeResponse" />
  </wsdl:operation>
  </wsdl:portType>
- <wsdl:binding name="EmployeeServiceHttpBinding" type="tns:EmployeeServicePortType">
  <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
- <wsdl:operation name="getEmployee">
  <wsdlsoap:operation soapAction="" />
- <wsdl:input name="getEmployeeRequest">
  <wsdlsoap:body use="literal" />
  </wsdl:input>
- <wsdl:output name="getEmployeeResponse">
  <wsdlsoap:body use="literal" />
  </wsdl:output>
  </wsdl:operation>
- <wsdl:operation name="addEmployee">
  <wsdlsoap:operation soapAction="" />
- <wsdl:input name="addEmployeeRequest">
  <wsdlsoap:body use="literal" />
  </wsdl:input>
- <wsdl:output name="addEmployeeResponse">
  <wsdlsoap:body use="literal" />
  </wsdl:output>
  </wsdl:operation>
- <wsdl:operation name="deleteEmployee">
  <wsdlsoap:operation soapAction="" />
- <wsdl:input name="deleteEmployeeRequest">
  <wsdlsoap:body use="literal" />
  </wsdl:input>
- <wsdl:output name="deleteEmployeeResponse">
  <wsdlsoap:body use="literal" />
  </wsdl:output>
  </wsdl:operation>
  </wsdl:binding>
- <wsdl:service name="EmployeeService">
- <wsdl:port name="EmployeeServiceHttpPort" binding="tns:EmployeeServiceHttpBinding">
  <wsdlsoap:address location="http://192.9.11.53:8080/employeeServiceForXfire/services/EmployeeService" />
  </wsdl:port>
  </wsdl:service>
  </wsdl:definitions>

posted on 2011-12-28 20:56 AthrunWang 阅读(324) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: