Spring Web Services 静态WSDL


在上一章Spring -WS - 第一个应用中,我们使用Spring WS Configuration自动生成了WSDL。在这种情况下,我们将展示如何使用Spring WS公开现有的WSDL。

序号 描述
1 在Spring WS-First Application章节中解释,在com.codingdict包下创建一个名为leaveService的项目。
2 在/ WEB-INF / wsdl子文件夹下创建WSDL leave.wsdl。
3 更新/ WEB-INF子文件夹下的spring-ws-servlet.xml。我们在这里使用static-wsdl标记而不是dynamic-wsdl。
4 最后一步是创建所有源文件和配置文件的内容,并导出应用程序,如下所述。

/WEB-INF/spring-ws-servlet.xml

<wsdl:definitions xmlns:wsdl = "http://schemas.xmlsoap.org/wsdl/"
   xmlns:soap = "http://schemas.xmlsoap.org/wsdl/soap/"
   xmlns:schema = "http://codingdict.com/hr/schemas"
   xmlns:tns = "http://codingdict.com/hr/definitions"
   targetNamespace = "http://codingdict.com/hr/definitions">

   <wsdl:types>
      <xsd:schema xmlns:xsd = "http://www.w3.org/2001/XMLSchema">
         <xsd:import namespace = "http://codingdict.com/hr/schemas"
            schemaLocation = "hr.xsd"/>
      </xsd:schema>
   </wsdl:types>

   <wsdl:message name = "LeaveRequest">
      <wsdl:part element = "schema:LeaveRequest" name = "LeaveRequest"/>
   </wsdl:message>

   <wsdl:portType name = "HumanResource">
      <wsdl:operation name = "Leave">
         <wsdl:input message = "tns:LeaveRequest" name = "LeaveRequest"/>
      </wsdl:operation>
   </wsdl:portType>

   <wsdl:binding name = "HumanResourceBinding" type = "tns:HumanResource">
      <soap:binding style = "document"
         transport = "http://schemas.xmlsoap.org/soap/http"/>
      <wsdl:operation name = "Leave">
         <soap:operation soapAction = "http://mycompany.com/RequestLeave"/>
         <wsdl:input name = "LeaveRequest">
            <soap:body use = "literal"/>
         </wsdl:input>
      </wsdl:operation>
   </wsdl:binding>

   <wsdl:service name = "HumanResourceService">
      <wsdl:port binding = "tns:HumanResourceBinding" name = "HumanResourcePort">
         <soap:address location = "http://localhost:8080/leaveService/"/>
      </wsdl:port>
   </wsdl:service>
</wsdl:definitions>

/WEB-INF/spring-ws-servlet.xml

<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.codingdict.hr"/>
   <sws:annotation-driven/>
   <sws:static-wsdl id = "leave" location = "/WEB-INF/wsdl/leave.wsdl"/>
</beans>

运行项目

完成创建源文件和配置文件后,我们应该导出应用程序。右键单击应用程序,使用Export→WAR File选项并将leaveService.war文件保存在Tomcat的webapps文件夹中。

现在,启动Tomcat服务器并确保我们可以使用标准浏览器从webapps文件夹访问其他网页。尝试访问URL - http://localhost:8080/leaveService/leave.wsdl , 如果Spring Web Application一切正常,我们将看到以下屏幕。

静态WSDL结果