2017-03-23 38 views

回答

2

在本教程中,他們採用了自下而上的方法。如果你想獲得WSDL在這個例子中

http://<host>:<port>/ws/countries.wsdl 

要得到國家的響應

$ curl --header "content-type: text/xml" -d @request.xml http://localhost:8080/ws 

下面是一個視頻解釋和說明找到了一個不錯的教程下request.xml

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
        xmlns:gs="http://spring.io/guides/gs-producing-web-service"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <gs:getCountryRequest> 
     <gs:name>Spain</gs:name> 
     </gs:getCountryRequest> 
    </soapenv:Body> 
</soapenv:Envelope> 
+1

謝謝,我檢查了它的產生。我覺得應該在某處明確提及這一點。 – minusSeven

2

對於自頂向下的方法,我們首先創建一個wsdl,然後使用wsdl生成所需的類。然後使用這些類來暴露一個web服務端點。

使用maven-jaxb2-plugin我們可以生成wsdl所需的必需類。

 <plugin> 
      <groupId>org.jvnet.jaxb2.maven2</groupId> 
      <artifactId>maven-jaxb2-plugin</artifactId> 
      <version>${maven-jaxb2-plugin.version}</version> 
      <executions> 
       <execution> 
        <goals> 
         <goal>generate</goal> 
        </goals> 
       </execution> 
      </executions> 
      <configuration> 
       <schemaDirectory>${project.basedir}/src/main/resources/wsdl</schemaDirectory> 
       <schemaIncludes> 
        <include>*.wsdl</include> 
       </schemaIncludes> 
      </configuration> 
     </plugin> 

接下來使用ServletRegistrationBean來註冊MessageDispatcherServlet和Spring Boot。在此註冊過程中,servlet映射URI模式設置爲/ javainuse/ws/*。使用此路徑,Web容器將傳入的HTTP請求映射到MessageDispatcherServlet。 DefaultWsdl11Definition使用指定的Hello World WSDL文件公開標準的WSDL 1.1。 MessageDispatcherServlet還會自動檢測在其應用程序上下文中定義的任何WsdlDefinition。

參考 - Spring Boot + SOAP Web Services Contract First Example