简体   繁体   English

使用wsdl2java和Spring的Web服务客户端

[英]Web service client using wsdl2java and Spring

I would like my Spring MVC based app to consume a web service. 我希望基于Spring MVC的应用程序可以使用Web服务。 Only thing I know about the service is it's WSDL. 我对服务唯一了解的是WSDL。

I'm using this example from W3C for testing purposes. 我将W3C中的此示例用于测试目的。

I'm able to generate client's java artifacts through WSDL2Java utility from CXF. 我可以通过CXF的WSDL2Java实用程序生成客户端的Java工件。 It gives me some interfaces and their implementations and some usage example in main method (but it's not much help for this purpose). 它为我提供了一些接口及其实现以及main方法中的一些用法示例(但为此目的并没有太大帮助)。

What configuration do I have to do in my app to simply integrate this client? 我必须在应用程序中进行什么配置才能简单地集成此客户端? I would prefer XML conf aproach. 我更喜欢XML conf方法。

Used versions are: 使用的版本是:

  • CXF 2.7.10 CXF 2.7.10
  • Spring 3.2.8 春季3.2.8

CXF has a <jaxws:client /> element that is used for configuring the client. CXF具有用于配置客户端的<jaxws:client />元素。

You specify an @WebService annotated Interface as the serviceClass property, and the endpoint URL as the address property. 您可以将@WebService批注的接口指定为serviceClass属性,并将端点URL指定为address属性。 For example, assuming wsdl2java generated com.w3schools.webservices.TempConvertSoap 例如,假设wsdl2java生成了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. 您可以将tempconvertClient bean作为com.w3schools.webservices.TempConvertSoap注入,并使用它进行服务调用。

For more information, see the CXF JAX-WS Configuration documentation. 有关更多信息,请参见CXF JAX-WS配置文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM