资讯专栏INFORMATION COLUMN

使用cxf-codegen-plugin实现WebServices客户端

Terry_Tai / 1698人阅读

摘要:服务搭建参见使用搭建服务端使用实现客户端创建工程添加,在选项中添加地址执行构建或自动构建,会自动生成相应的客户端代码例如调用,如下执行成功,得到如下结果

WebServices服务搭建参见:使用CXF搭建WebServices服务端

使用cxf-codegen-plugin实现WebServices客户端

1 创建maven工程

添加cxf-codegen-plugin,在选项中添加wsdl地址


    4.0.0
    com.liubo
    text-cxf-client
    0.0.1-SNAPSHOT

    
        UTF-8
    

    
        
            
                org.apache.maven.plugins
                maven-compiler-plugin
                2.3.2
                
                    1.6
                    1.6
                    UTF-8
                
            
            
                org.apache.maven.plugins
                maven-surefire-plugin
                2.7.2
                
                    once
                    -Dfile.encoding=UTF-8
                    
                        
                            net.sourceforge.cobertura.datafile
                            target/cobertura/cobertura.ser
                        
                    
                
            
            
                org.apache.cxf
                cxf-codegen-plugin
                2.7.3
                
                    
                        generate-sources
                        generate-sources
                        
                            ${project.build.sourceDirectory}
                            UTF-8
                            
                                
                                    http://localhost:8080/test-cxf/HelloWS?wsdl
                                
                            
                        
                        
                            wsdl2java
                        
                    
                
            
        
    

2 执行maven构建(或自动构建),maven会自动生成相应的WebServices客户端代码

例如HelloWebService

package com.liubo.test.cxf.service;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;

/**
 * This class was generated by Apache CXF 2.7.3
 * 2016-04-28T18:53:56.903+08:00
 * Generated source version: 2.7.3
 * 
 */
@WebService(targetNamespace = "http://service.cxf.test.liubo.com/", name = "HelloWebService")
@XmlSeeAlso({ObjectFactory.class})
public interface HelloWebService {

    @WebResult(name = "return", targetNamespace = "")
    @RequestWrapper(localName = "sayHello", targetNamespace = "http://service.cxf.test.liubo.com/", className = "com.liubo.test.cxf.service.SayHello")
    @WebMethod
    @ResponseWrapper(localName = "sayHelloResponse", targetNamespace = "http://service.cxf.test.liubo.com/", className = "com.liubo.test.cxf.service.SayHelloResponse")
    public java.lang.String sayHello(
        @WebParam(name = "text", targetNamespace = "")
        java.lang.String text
    );
}

3 调用WebService,如下

package com.liubo.test.cxf.client;

import com.liubo.test.cxf.service.HelloWebService;
import com.liubo.test.cxf.serviceimpl.HelloWS;

public class Client {

    public static void main(String[] args) {
        
        HelloWS factory = new HelloWS();

        HelloWebService helloWebService = factory.getHelloWebServiceImplPort();

        System.out.println(helloWebService.sayHello("Libra"));
    }
}

执行成功,得到如下结果

hello Libra, welcome to the real world

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/65855.html

相关文章

  • 使用CXF搭建WebServices服务端

    摘要:使用创建工程,引入和,如下在中配置和创建要提供服务接口和实现接口类实现类配置文件注意引入和,然后添加要提供的接口信息全文如下配置完成后,部署到,启动访问即可看到服务已成功发布。客户端实现见下文使用实现客户端 1 使用Maven创建Java Web工程,引入cxf和spring,pom.xml如下 4.0.0 com.liubo test-cxf 0.0...

    hatlonely 评论0 收藏0
  • 使用 Apache cxf 实现 WebService 户端

    摘要:证书有两种形式指定路径有三种形式的插件可以指定参数来解决一下常见的问题下的可以选择所需的命令参数使用参考添加解决中命名冲突添加指定自动生成的包名 ws-client-demo 客户端调用远程服务 http://localhost:8280/services/HelloWorld?wsdl spring + cfx 配置 maven 添加依赖包 org.apache.cxf c...

    mingzhong 评论0 收藏0
  • WebService就是这么简单

    摘要:它使用方式,接收和响应外部系统的某种请求。回顾我们在学习基础网络编程章节已经知道了这么一个连接了。使用指定名称的命名空间。名词简单对象访问协议作为一个基于语言的协议用于有网上传输数据。以的根元素出现。代理这么一个概念就更加清晰了。 WebService介绍 首先我们来谈一下为什么需要学习webService这样的一个技术吧.... 问题一 如果我们的网站需要提供一个天气预报这样一个需求...

    SwordFly 评论0 收藏0
  • PHP设计模式范例 — DesignPatternsPHP(2)结构型设计模式

    摘要:此模式的主要特点是,与不同,其数据模式遵循单一职责原则。图代码你可以在上找到这些代码代理模式目的为昂贵或者无法复制的资源提供接口。图代码你可以在上找到这些代码相关文章设计模式范例创建型设计模式 【搬运于GitHub开源项目DesignPatternsPHP】 项目地址:戳我 2、结构型设计模式 在软件工程中,结构型设计模式集是用来抽象真实程序中的对象实体之间的关系,并使这种关系可被描...

    princekin 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<