如何将现有的肥皂网服务用于春季申请?

时间:2016-03-12 13:10:05

标签: java soap

我是Soap网络服务的新手,我现有肥皂网服务网址,如下所示

http://mywebservice/firstwsdl.asmx?wsdl

我想在我的项目中使用这个网络服务。我怎么能这样做,任何人帮助我。在我的项目中我也使用Maven。

先谢谢。

1 个答案:

答案 0 :(得分:1)

以下步骤可以让您了解从哪里开始第一次使用肥皂服务 -

<强> 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 annotations在marshaller bean包中指定的包下提供 - 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();
        }
    }