Вопрос

I would like my Spring MVC based app to consume a web service. Only thing I know about the service is it's WSDL.

I'm using this example from W3C for testing purposes.

I'm able to generate client's java artifacts through WSDL2Java utility from CXF. It gives me some interfaces and their implementations and some usage example in main method (but it's not much help for this purpose).

What configuration do I have to do in my app to simply integrate this client? I would prefer XML conf aproach.

Used versions are:

  • CXF 2.7.10
  • Spring 3.2.8
Это было полезно?

Решение

CXF has a <jaxws:client /> element that is used for configuring the client.

You specify an @WebService annotated Interface as the serviceClass property, and the endpoint URL as the address property. For example, assuming wsdl2java generated com.w3schools.webservices.TempConvertSoap

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:jaxws="http://cxf.apache.org/jaxws"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
          http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans.xsd
          http://cxf.apache.org/jaxws
          http://cxf.apache.org/schemas/jaxws.xsd">

    <jaxws:client id="tempconvertClient"
                  serviceClass="com.w3schools.webservices.TempConvertSoap"
                  address="http://www.w3schools.com/webservices/tempconvert.asmx" />
</beans>

You can inject the tempconvertClient bean as com.w3schools.webservices.TempConvertSoap, and use it to make your service calls.

For more information, see the CXF JAX-WS Configuration documentation.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top