Spring Web Service客户端教程或示例必需 [英] Spring Web Service Client Tutorial or Example Required

查看:146
本文介绍了Spring Web Service客户端教程或示例必需的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要跳进Spring Web Service Project,因为我需要实现Spring Web Service的Client ..

I need to jump into the Spring Web Service Project, in that I required to implement the Spring Web Service's Client Only..

所以,我已经经历过了使用 Spring的客户参考文档

So, I have already gone through with Spring's Client Reference Document.

所以,我知道实现客户端所需的类。

So, I got the idea of required classes for the implementation of Client.

但我的问题就像我做的那样一些谷歌搜索,但没有得到客户端和服务器的任何正确的例子,因为我可以为我的客户实现一个样本。

But my problem is like I have done some googling, but didn't get any proper example of both Client and Server from that I can implement one sample for my client.

所以,如果有人给我一些链接或者教程中的正确示例,我可以了解我的客户端实现将非常感谢。

So, if anybody gives me some link or tutorial for proper example from that I can learn my client side implementation would be greatly appreciated.

提前致谢...

推荐答案

在我以前的项目中,我用Spring 2.5.6,maven2,xmlbeans实现了一个Webservice客户端。

in my previous project, I implemented a Webservice client with Spring 2.5.6, maven2, xmlbeans.


  • xmlbeans是respo un / marshal

  • maven2用于项目管理/建筑等。

我粘贴这里有一些代码,希望它们有用。

I paste some codes here and hope they are helpful.

xmlbeans maven插件conf :(在pom.xml中)

xmlbeans maven plugin conf: (in 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中,你需要放置模式文件(独立或在你的WSDL文件中) ,你需要提取它们并保存为模式文件。)在src / main / resources下。当您使用maven构建项目时,pojos将由xmlbeans生成。生成的源代码将在
target / generated-sources / xmlbeans下。

So from the above conf, you need to put the schema file (either standalone or in your WSDL file, you need to extract them and save as a schema file.) under src/main/resources. when you build the project with maven, the pojos are gonna be generated by xmlbeans. The generated sourcecodes will be under target/generated-sources/xmlbeans.

然后我们来到Spring conf。我只是把WS相关的上下文放在这里:

then we come to Spring conf. I just put the WS relevant context here:

    <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 class

finally, take a look the ws-client java class

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.

   }

}

我希望示例代码有用。

这篇关于Spring Web Service客户端教程或示例必需的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆