spring-ws的使用

来源:互联网 发布:数据三国 编辑:程序博客网 时间:2024/06/05 02:50

原文来源  http://download.csdn.net/download/xiezhipu/8043933


  业务接口

public interface HumanResourceService {
    void bookHoliday(Date startDate, Date endDate, String name);
}

业务接口实现

@Service                                                                                 
public class StubHumanResourceService implements HumanResourceService {
    public void bookHoliday(Date startDate, Date endDate, String name) {
        System.out.println("Booking holiday for [" + startDate + "-" + endDate + "] for [" + name + "] ");
    }
}



webservice 配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:sws="http://www.springframework.org/schema/web-services"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services-2.0.xsd
  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

  <context:component-scan base-package="com.mycompany.hr"/>

  <sws:annotation-driven/>
 
  <sws:dynamic-wsdl id="holiday"                                                           
    portTypeName="HumanResource"                                                        
    locationUri="/holidayService/"                                                       
    targetNamespace="http://mycompany.com/hr/definitions">                               
  <sws:xsd location="/WEB-INF/hr.xsd"/>                                                 
</sws:dynamic-wsdl>

</beans>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
         version="2.4">

    <display-name>Archetype Created Web Application</display-name>

    <servlet>
        <servlet-name>spring-ws</servlet-name>
        <servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
        <init-param>
              <param-name>transformWsdlLocations</param-name>
              <param-value>true</param-value>
        </init-param>
    </servlet>

    <servlet-mapping>
        <servlet-name>spring-ws</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
    


</web-app>

报文声明

<?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"

        xmlns:hr="http://mycompany.com/hr/schemas"

        elementFormDefault="qualified"

        targetNamespace="http://mycompany.com/hr/schemas">

    <xs:element name="HolidayRequest">

        <xs:complexType>

            <xs:all>

                <xs:element name="Holiday" type="hr:HolidayType"/>                       

                <xs:element name="Employee" type="hr:EmployeeType"/>

            </xs:all>

        </xs:complexType>

    </xs:element>

    <xs:complexType name="HolidayType">

        <xs:sequence>

            <xs:element name="StartDate" type="xs:date"/>

            <xs:element name="EndDate" type="xs:date"/>                                 

        </xs:sequence>                                                                   

    </xs:complexType>

    <xs:complexType name="EmployeeType">

        <xs:sequence>

            <xs:element name="Number" type="xs:integer"/>

            <xs:element name="FirstName" type="xs:string"/>

            <xs:element name="LastName" type="xs:string"/>                              

        </xs:sequence>                                                                   

    </xs:complexType>

</xs:schema







0 1
原创粉丝点击