Apache CXF + Spring: Generating a Simple Client

后端 未结 2 1418
北海茫月
北海茫月 2021-01-18 14:27

I\'ve started learning the Apache CXF with Spring. First of all, I\'ve tried to create a simple client/server model.

The server-side is: service.Hel

相关标签:
2条回答
  • 2021-01-18 14:49

    If you are doing code-first WS development then it is fine to distribute the interface and give it to the client. I believe @WebService is not needed (?) on the interface (only implementation), so the client does not have dependencies on this annotation.

    Even if you are doing code-first web-services, you may still download the WSDL document generated for you by Apache CXF and give it to the client instead. With this approach (which is considered more mature, not to mention it can be used on different platforms like .NET) the client has to generate the stubs (using tool like wsdl2java). This process will essentially create very similar client interface automatically.

    That's one of the reasons why so many people prefer contract-first development - the same WSDL is used to generate client-side stubs and server-side WS implementation. This limits the scope of (accidental) incompatibilites.

    0 讨论(0)
  • 2021-01-18 15:01

    You can use a simple spring configuration like this for client side -

    <jaxws:client id="mywebServiceClient"
        serviceClass="com.saurzcode.TestService"
        address="http://saurzcode.com:8088/mockTestService">
    
        <jaxws:binding>
            <soap:soapBinding version="1.2" mtomEnabled="true" />
        </jaxws:binding>
    </jaxws:client>
    <cxf:bus>
        <cxf:outInterceptors>
            <bean class="com.saurzcode.ws.caller.SoapHeaderInterceptor" />
        </cxf:outInterceptors>
    </cxf:bus>
    

    Ignore the Interceptor if you don't need it.

    More details in this post.

    0 讨论(0)
提交回复
热议问题