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("http://業務想咋整自已實現去吧,我這里作例子,就直接回true了,呵呵");
                  e.setId("http://業務想咋整自已實現去吧,我這里作例子,就直接回true了,呵呵");
                  e.setName("http://業務想咋整自已實現去吧,我這里作例子,就直接回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 閱讀(329) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 浮山县| 德州市| 上栗县| 临沧市| 黄龙县| 拉萨市| 化德县| 海宁市| 民县| 浮梁县| 永兴县| 中牟县| 湖南省| 英山县| 安陆市| 胶州市| 汪清县| 林周县| 石门县| 泰兴市| 吴桥县| 吐鲁番市| 孟州市| 韶山市| 十堰市| 建昌县| 韶关市| 泗洪县| 永顺县| 旅游| 南昌县| 时尚| 阜宁县| 蓝山县| 阆中市| 安多县| 简阳市| 泸西县| 富源县| 临潭县| 个旧市|