我需要跳进Spring Web Service Project,因为我需要实现Spring Web Service的Client ..
所以,我已经完成了Spring's Client Reference Document。
因此,我了解了实现Client的必需类。
但我的问题就像我做了一些谷歌搜索,但没有得到客户端和服务器的任何正确的例子,因为我可以为我的客户端实现一个样本。
所以,如果有人给我一些链接或教程,我可以从中了解到我的客户端实现将非常感谢。
提前致谢...
答案 0 :(得分:10)
分步教程 - 使用Spring-WS @的Web服务客户端 http://justcompiled.blogspot.com/2010/11/web-service-client-with-spring-ws.html
答案 1 :(得分:7)
在我之前的项目中,我使用Spring 2.5.6,maven2,xmlbeans实现了一个Webservice客户端。
我在这里粘贴一些代码并希望它们有用。
xmlbeans maven插件conf :(在pom.xml中)
<build>
<finalName>projectname</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>target/generated-classes/xmlbeans
</directory>
</resource>
</resources>
<!-- xmlbeans maven plugin for the client side -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xmlbeans-maven-plugin</artifactId>
<version>2.3.2</version>
<executions>
<execution>
<goals>
<goal>xmlbeans</goal>
</goals>
</execution>
</executions>
<inherited>true</inherited>
<configuration>
<schemaDirectory>src/main/resources/</schemaDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin
</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source> target/generated-sources/xmlbeans</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
因此,从上面的conf中,您需要在src / main / resources下放置模式文件(独立或在您的WSDL文件中,您需要提取它们并保存为模式文件。)。当你使用maven构建项目时,pojos将由xmlbeans生成。生成的源代码将在 目标/生成-源/的xmlbeans。
然后我们来到Spring conf。我只是把WS相关的上下文放在这里: <bean id="messageFactory" class="org.springframework.ws.soap.axiom.AxiomSoapMessageFactory">
<property name="payloadCaching" value="true"/>
</bean>
<bean id="abstractClient" abstract="true">
<constructor-arg ref="messageFactory"/>
</bean>
<bean id="marshaller" class="org.springframework.oxm.xmlbeans.XmlBeansMarshaller"/>
<bean id="myWebServiceClient" parent="abstractClient" class="class.path.MyWsClient">
<property name="defaultUri" value="http://your.webservice.url"/>
<property name="marshaller" ref="marshaller"/>
<property name="unmarshaller" ref="marshaller"/>
</bean>
最后,看看ws-client java类
public class MyWsClient extends WebServiceGatewaySupport {
//if you need some Dao, Services, just @Autowired here.
public MyWsClient(WebServiceMessageFactory messageFactory) {
super(messageFactory);
}
// here is the operation defined in your wsdl
public Object someOperation(Object parameter){
//instantiate the xmlbeans generated class, infact, the instance would be the document (marshaled) you are gonna send to the WS
SomePojo requestDoc = SomePojo.Factory.newInstance(); // the factory and other methods are prepared by xmlbeans
ResponsePojo responseDoc = (ResponsePojo)getWebServiceTemplate().marshalSendAndReceive(requestDoc); // here invoking the WS
//then you can get the returned object from the responseDoc.
}
}
我希望示例代码有用。