一、生成客户端代码:
当编写完成服务器端代码后,则可通过命令自动生成客户端代码。
wsdl2java -p ws.client -d E:\eclipse_workspace\src -verbose http://localhost:8080/TestService?wsdl
各参数详解见:http://cwiki.apache.org/CXF20DOC/wsdl-to-java.html
注:在使用该命令生成的客户端代码时,代码可能会报错,这是由于CXF中与原项目中存在相同的名称的jar包,解决此问题有三种方法:
1、将项目中的CXF的包提到项目最前端。
2、将报错代码删除(一般不影响正常使用)。
3、使用降低版本规约的方法生成客户端代码,命令如下:
wsdl2java -frontend jaxws21 -p ws.client -d E:\eclipse_workspace\src -verbose http://localhost:8080/TestService?wsdl
说明:该命令生成的客户端代码与使用第二种处理方法的代码完全一致。
二、测试:
到这里一个简单的Web Services应用程序就已经搭建完成了,现在就来进行一下测试,看能否正常执行。
1、在测试项目中新建bean.xml文件,并进行客户端代码配置,代码如下:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd" default-autowire="byName"> <jaxws:client id="testService" serviceClass="ws.client.ITestService" address="http://my.cogobuy.com:8080/TestService"/> </beans>
2、建新测试方法,代码如下:
public class TestClent { /* 客户端service */ private ITestService testService; /** * @Description * @throws java.lang.Exception * @return void * @throws */ @Before public void setUp() throws Exception { ApplicationContext context = new ClassPathXmlApplicationContext("bean.xml"); testService = (ITestService) context.getBean("testService"); } @Test public void test01() throws Exception { TestUser user = testService.getUserProperty("awbqty_zhang", "123456"); System.out.println(user.getName() + " " + user.getEnName() + " " + user.getPhone() + " "+ user.getMail() + " "+ user.getNickName()); } }
相关推荐
CXF+spring+struts实现WebService
CXF2.6+SPRING3.0+STRUTS2.3整合的一个例子,含Jar包.
完整的cxf+hibernate+spring实现 weblogic 和tomcat上完美兼容
忘记删除个人的资料了,现在重新传一个,供大家学习使用,互相交流,资源内容 为rar格式的 项目,cxf 为服务器端,cxfTest 为客户端,里边有很多调用方式,还有身份验证,使用时,搭配好 客户端和服务端的spring ...
CXF2+Spring2.5开发WebService实例,需要导入jar包
NULL 博文链接:https://devon-k.iteye.com/blog/1136650
NULL 博文链接:https://chilongxph.iteye.com/blog/510707
利用CXF3.0+Spring3.2 HelloWorld实例,并且导入了小量的jar包以及在写例子的过程中遇见的一些错误!
CXF2.5.0+Spring2.5 集成DEMO
利用CXF3.0.2+Spring3.2.14发布RESTFul,传递json数据格式的!需要源代码可以下载!
CXF Restful + Spring3 + Mybatis 后台开发环境搭建
webService实现 cxf2.7.5 与 spring3.0集成 完整流程,内涵全部jar ,下载集合运行
利用CXF3.0.2+Spring3.2.14发布WSSecurity!需要源代码可以下载!
利用CXF3.0.2+Spring3.2.14发布RESTFul,有源代码可以下载!
cxf+spring+client+springmvc
利用CXF3.0.2+Spring3.2.14传输文件,里面有笔者在练习过程中遇到的错误,还有源代码可以下载!
cxfserver+spring+mybatis
简单的webservice+Cxf+Spring数据对接实例以及jar.rar简单的webservice+Cxf+Spring数据对接实例以及jar.rar简单的webservice+Cxf+Spring数据对接实例以及jar.rar简单的webservice+Cxf+Spring数据对接实例以及jar.rar...
cxf3 + spring4,使用配置的方式发布webservice