2016-03-12 54 views

回答

1

按照以下幾個步驟可以讓你知道從哪裏開始你的第一個SOAP服務 -

1.添加依賴關係到你的pom

<dependencies> 
    <dependency> 
     <groupId>org.springframework.ws</groupId> 
     <artifactId>spring-ws-core</artifactId> 
     <version>2.1.3.RELEASE</version> 
    </dependency> 
    <dependency> 
     <groupId>javax.xml.bind</groupId> 
     <artifactId>jaxb-api</artifactId> 
     <version>2.2.12</version> 
    </dependency> 
    </dependencies> 

2.使用Maven插件生成存根

<plugin> 
      <groupId>org.jvnet.jaxb2.maven2</groupId> 
      <artifactId>maven-jaxb2-plugin</artifactId> 
      <executions> 
       <execution> 
        <goals> 
         <goal>generate</goal> 
        </goals> 
       </execution> 
      </executions> 
      <configuration> 
       <schemaLanguage>WSDL</schemaLanguage> 
       <generatePackage>com.test.package.stub</generatePackage> 
       <forceRegenerate>true</forceRegenerate> 
       <schemas> 
        <schema> 
         <url>http://mywebservice/firstwsdl.asmx?wsdl</url> 
        </schema> 
       </schemas> 
      </configuration> 
     </plugin> 
     </plugins> 

3.添加到您的春季應用程序陽離子上下文

<?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:oxm="http://www.springframework.org/schema/oxm" xmlns:util="http://www.springframework.org/schema/util" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> 

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

    <!-- Define the SOAP version used by the WSDL --> 
    <bean id="soapMessageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory"> 
     <property name="soapVersion"> 
      <util:constant static-field="org.springframework.ws.soap.SoapVersion.SOAP_12"/> 
     </property> 
    </bean> 

    <!-- The location of the generated Java files --> 
    <oxm:jaxb2-marshaller id="marshaller" contextPath="com.test.package.stub"/> 

    <!-- Configure Spring Web Services --> 
    <bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate"> 
     <constructor-arg ref="soapMessageFactory"/> 
     <property name="marshaller" ref="marshaller"/> 
     <property name="unmarshaller" ref="marshaller"/> 
     <property name="defaultUri" value="http://mywebservice/hello"/> 
    </bean> 
</beans> 

4.最後你的服務類

請求和響應班會您在編組豆包JAXB批註指定的包下可用 - com.test.package.stub :

@Service 
    public class TestService { 
     @Autowired 
     private WebServiceTemplate webServiceTemplate; 

     public Double getValue(String paramOne) { 

      request.setParam(paramOne); 

      Response response = (Response) webServiceTemplate.marshalSendAndReceive(
        request); 

      return response.Result(); 
     } 
    } 
相關問題