6

Spring Web サービスのクライアントのみを実装する必要があるという点で、Spring Web サービス プロジェクトに飛び込む必要があります。

そのため、 Spring の Client Reference Document については既に説明しました。

それで、クライアントの実装に必要なクラスのアイデアを得ました。

しかし、私の問題は、グーグルを行ったようですが、クライアントとサーバーの両方の適切な例が得られなかったため、クライアントに1つのサンプルを実装できませんでした。

したがって、誰かが適切な例のリンクまたはチュートリアルを提供してくれれば、クライアント側の実装を学ぶことができます。

前もって感謝します...

4

2 に答える 2

10

ステップ バイ ステップ チュートリアル - Spring-WS を使用した Web サービス クライアント @ http://justcompiled.blogspot.com/2010/11/web-service-client-with-spring-ws.html

于 2010-11-07T06:33:48.677 に答える
7

以前のプロジェクトでは、Spring 2.5.6、maven2、xmlbeansを使用してWebサービスクライアントを実装しました。

  • xmlbeansはun/marshalを担当します
  • maven2はプロジェクト管理/建物など用です。

ここにいくつかのコードを貼り付けて、それらが役立つことを願っています。

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を使用してプロジェクトをビルドすると、pojoはxmlbeansによって生成されます。生成されたソースコードは、target /generated-sources/xmlbeansの下にあります。

それから私たちは春の会議に来ます。ここに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-clientjavaクラスを見てください

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.

   }

}

サンプルコードがお役に立てば幸いです。

于 2010-03-09T13:35:36.127 に答える