码迷,mamicode.com
首页 > Web开发 > 详细

使用cxf调用webservice

时间:2016-06-23 22:13:16      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:

1、引入maven包

技术分享
<dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>${cxf.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>${cxf.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http-jetty</artifactId>
            <version>${cxf.version}</version>
        </dependency>
View Code

2、创建Client对象

技术分享
public static Client getDynamicClient(String wsdlUrl) {
        if (client == null) {
            synchronized (this.class) {
                if (client == null) {
                    DynamicClientFactory dcf = DynamicClientFactory.newInstance();
                    client = dcf.createClient(wsdlUrl);
                }
            }
        }
        return client;
    }
View Code

3、请求远程方法

技术分享
    private String getResult(String reqXml, String wsdlUrl, String method) {
        String result = null;
        Object[] objects = null;
        try {
            LOGGER.debug("reqXml={}.", reqXml);
            objects = getDynamicClient(wsdlUrl).invoke(method, reqXml);
            result = (String) objects[0];
            LOGGER.debug("GbotExecutor.getResult response={}.", result);
        }
        catch (Exception e) {
            LOGGER.error("invoke gbot getResult failed!", e);
        }
        return result;
    }
View Code

 

使用cxf调用webservice

标签:

原文地址:http://www.cnblogs.com/BensonHe/p/5612117.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!