上篇博客介绍了,cxf的soap风格的服务端,现在我们写客户端来调用

1、pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>com.jacky</groupId>
<artifactId>cxf_client</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging> <name>cxf_client</name>
<url>http://maven.apache.org</url> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-common</artifactId>
<version>2.5.4</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-core</artifactId>
<version>2.6.1</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>2.6.1</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

2.Info.xml

package com.jacky;

public class Info {
private String name;
private int age;
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public int getAge()
{
return age;
}
public void setAge(int age)
{
this.age = age;
}
@Override
public String toString() {
return "Info [name=" + name + ", age=" + age + "]";
} }

3、App.java

package com.jacky;

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.junit.Test; import com.jacky.service.GetInfoService; /**
* Hello world!
*
*/
public class App {
/**
* 简介:调用方式采用了和RMI类似的机制,即客户端直接服务器端提供的服务接口(interface),
* CXF通过运行时代理生成远程服务的代理对象,
* 在客户端完成对webservice的访问;几个必填的字段:
* setAddress-这个就是我们发布webservice时候的地址,保持一致。
缺点:这种调用service的好处在于调用过程非常简单,就几行代码就完成一个webservice的调用,
* 但是客户端也必须依赖服务器端的接口,这种调用方式限制是很大的,
* 要求服务器端的webservice必须是java实现--这样也就失去了使用webservice的意义。
*/
@Test
public void test1(){
JaxWsProxyFactoryBean bean = new JaxWsProxyFactoryBean();
bean.setServiceClass(GetInfoService.class);
bean.setAddress("http://localhost:8080/cxf_demo/cxf/getInfoService");
GetInfoService service = (GetInfoService)bean.create();
int result = service.add(1, 1);
System.out.println("result====="+result);
Info info = service.getInfo("罗志茂", 21);
System.out.println("info==="+info);
}
/**
* 简介:只要指定服务器端wsdl文件的位置,然后指定要调用的方法和方法的参数即可,不关心服务端的实现方式。
* wsdl [Web Services Description Language]网络服务描述语言是Web Service的描述语言,它包含一系列描述某个web service的定义
* @throws Exception
*/
@Test
public void test2() throws Exception {
JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory.newInstance();
Client client = clientFactory.createClient("http://localhost:8080/cxf_demo/cxf/getInfoService?wsdl");
Object[] objs ={1,2};
Object[] result = client.invoke("add", objs);
System.out.println(result[0]);
}
}

在这里cxf soap客户端的两种调用方式就写好了

链接:http://pan.baidu.com/s/1mi376Es 密码:ljy6

欢迎关注

cxf的soap风格+spirng4+maven 客户端的更多相关文章

  1. cxf的soap风格+spirng4+maven 服务端

    简介 SOAP 比较复杂,基于XML,有对应规范:REST利用HTTP请请求方式GET,POST,PUT,delete约定具体操作.简单的说,SOAP通过传输XML,XML定义了请求和响应的具体数据, ...

  2. idea+maven+spring+cxf创建webservice应用(二)生成客户端程序

    idea+maven+spring+cxf创建webservice应用(二)生成客户端程序,以上一篇为基础"idea+maven+spring+cxf创建webservice应用" ...

  3. 用cxf开发restful风格的WebService

    我们都知道cxf还可以开发restful风格的webService,下面是利用maven+spring4+cxf搭建webService服务端和客户端Demo 1.pom.xml <projec ...

  4. WebService- 使用 CXF 开发 SOAP 服务

    选框架犹如选媳妇,选来选去,最后我还是选了“丑媳妇(CXF)”,为什么是它?因为 CXF 是 Apache 旗下的一款非常优秀的 WS 开源框架,具备轻量级的特性,而且能无缝整合到 Spring 中. ...

  5. CXF wsdl2java 生成java代码供客户端使用

    CXF wsdl2java 生成java代码供客户端使用 环境配置:1.下载apache-cxf-2.6.2在环境变量中配置CXF_HOME 值为E:\gavin\cxf\apache-cxf-3.0 ...

  6. 使用cxf 发布 jax-rs 风格webservice 。并客户端测试。

    详细介绍:http://www.ibm.com/developerworks/cn/java/j-lo-jaxrs/ 1.定义一个User对象 package com.zf.test; import  ...

  7. CXF WebService整合SpringMVC的maven项目

    首先推荐博客:http://www.cnblogs.com/xdp-gacl/p/4259481.html   http://blog.csdn.net/hu_shengyang/article/de ...

  8. 使用Apache CXF开发WebServices服务端、客户端

    在前一篇的博客中,我使用Xfire1.x来开发了WebServies的服务端. 但是如果你访问Apache的官网,可以看到xfire已经被合并了. 最新的框架叫做CXF. Apache CXF = C ...

  9. cxf+spring+soap简单接口开发

    最近学了cxf框架开发webservice,简单搭了个接口,方便后续翻阅,本人才疏学浅,若有不足,请多多谅解! 一.服务端: 1.所用到的jar包: maven的pom.xml配置: <proj ...

随机推荐

  1. 协程并发框架gevent及其用法

    gevent是python的一个并发框架,采用协程实现并发目的,用起来也非常简单 gevent的docs:http://www.gevent.org/contents.html 一个最简单的例子: i ...

  2. VMware安装的相关文章

    1.在虚拟机中安装CentOS7(百度文库) 2.VM虚拟机下安装Centos7.0图文教程(centos中文站) 2016年8月10日11:30:03

  3. MySql超新手入门

    https://www.kancloud.cn/thinkphp/mysql-tutorial/36457

  4. ROW_NUMBER

    16:23 2015/4/16 删除重复数据,连续被两位同事问到完全相同的重复记录如何删除只保留一条 create table del_samerecords (id )) go insert int ...

  5. Gradle Cheat Sheet

    加快编译速度 使用 gradle 2.4 及以上版本 ~/.gradle/gradle.properties 加入如下配置 org.gradle.daemon=true org.gradle.jvma ...

  6. ubuntu 下安装 wxpython2.8

    echo "deb http://archive.ubuntu.com/ubuntu wily main universe" | sudo tee /etc/apt/sources ...

  7. [原创]如何设计Lighthoused定位接收电路

    本文使用最新出来的专用芯片TS3633 1)电路设计说明 1.电源电路 利用LM317低线性稳压芯片将5V或者12V的电源电压稳压到3.3V为TS3633提供工作电压.其中,磁珠L1主要用于抑制电源线 ...

  8. csuoj 1505: 酷酷的单词

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1505 1505: 酷酷的单词 时间限制: 1 Sec  内存限制: 128 MB 提交: 340  ...

  9. sdutoj 2606 Rubik’s cube

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2606 Rubik’s cube Time Li ...

  10. es5.0安装问题

    ES的5.0版本听说在性能上大大优化,于是老大说准备换5.0版本.由于在技术群看到很多人都说ES 5.0 安装有问题,在这里贴出自己在使用最新版5.0遇到的问题和解决方法 1.Elasticsearc ...