---
title: "Apache CXF客户端编写"
author: "卡拉阿风"
date: "2011-07-14T16:09:52Z"
tags: []
categories: ["企业架构"]
slug: "apache-cxf"
draft: false
lastmod: "2011-07-14T16:10:54Z"
id: 1124448
url: "https://alimama.iteye.com/blog/1124448"
---

拥有远程服务的接口与相关的DTO文件后(合作方给予或由WSDL生成)，有两种方法编写客户端:

a) 使用在spring的applicationContext中定义: 

 

```
<jaxws:client id="infoWebService" serviceClass="com.iteye.examples.infos.ws.InfoWebService" address="http://localhost:8080/examples/ws/infoservice"></jaxws:client>
```

 

b)使用JAXWS的API动态创建:

 

```
JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
		proxyFactory.setAddress(address);
		proxyFactory.setServiceClass(InfoWebService.class);
		InfoWebService infoWebService = (InfoWebService) proxyFactory.create();
```

 

**备注：address需要和jax-ws endpoint定义的address一样**

例如使用了 http://localhost:8080/examples/ws/InfoService 字母大小写

服务器会报

```
warn [org.apache.cxf.transport.servlet.ServletController] - Can't find the request for http://localhost:8080/examples/ws/InfoService's Observer
```