Nir*_*mal 6 java spring spring-ws java-ee
我需要跳进Spring Web Service Project,因为我需要实现Spring Web Service的Client Only ..
所以,我已经使用了Spring的客户参考文档.
所以,我了解了Client实现所需的类.
但我的问题就像我做了一些谷歌搜索,但没有得到客户端和服务器的任何正确的例子,因为我可以为我的客户端实现一个示例.
所以,如果有人给我一些链接或教程的正确示例,我可以了解我的客户端实现将不胜感激.
提前致谢...
Sha*_*med 10
一步一步的教程 - 使用Spring-WS的Web服务客户端@ http://justcompiled.blogspot.com/2010/11/web-service-client-with-spring-ws.html
在我之前的项目中,我使用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>
Run Code Online (Sandbox Code Playgroud)
因此,从上面的conf中,您需要在src/main/resources下放置模式文件(独立或在您的WSDL文件中,您需要提取它们并保存为模式文件.).当你使用maven构建项目时,pojos将由xmlbeans生成.生成的源代码将位于target/generated-sources/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>
Run Code Online (Sandbox Code Playgroud)
最后,看看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.
}
Run Code Online (Sandbox Code Playgroud)
}
我希望示例代码有用.
| 归档时间: |
|
| 查看次数: |
52223 次 |
| 最近记录: |