gpt4 book ai didi

java - 如何将现有的soap web服务使用到spring应用程序中?

转载 作者:行者123 更新时间:2023-12-01 10:14:53 25 4
gpt4 key购买 nike

我是 Soap Web 服务的新手,我有如下所示的现有 Soap Web 服务 URL

<强> http://mywebservice/firstwsdl.asmx?wsdl

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

提前致谢。

最佳答案

以下步骤可以让您了解从哪里开始您的第一个 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插件生成 stub

<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。添加到您的 Spring 应用程序上下文

<?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 注释的编码器 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();
}
}

关于java - 如何将现有的soap web服务使用到spring应用程序中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35958034/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com