CXF 2.0 学习笔记-1(服务端) 中生成了服务端,现在把服务端的wsdl保存到本地(直接把Http://xxx/ws/xxx?wsdl 另存为wsdl文件) 。
我们要根据服务端的wsdl来生成客户端调用的文件,这样需要用到CXF BIN目录下wsdl2java.bat 。
wsdl2java 参数如下:
wsdl2java -fe <frontend name>* -db <data binding name>* -wv <[wsdl version]>*
-p <[wsdl namespace =]Package Name>* -sn <service-name> -b <binding-name>*
-catalog <catalog-file-name> -d <output-directory> -compile
-classdir <compile-classes-directory> -impl -server -client -all
-autoNameResolution -defaultValues<=class name for DefaultValueProvider> -ant
-nexclude <schema namespace [= java packagename]>* -exsh <(true, false)>
-dns <(true, false)> -dex <(true, false)> -validate -keep
-wsdlLocation <wsdlLocation attribute> -xjc<xjc arguments> -noAddressBinding -h
-v -verbose -quiet <wsdlurl>
-p <[wsdl namespace =]Package Name>* -sn <service-name> -b <binding-name>*
-catalog <catalog-file-name> -d <output-directory> -compile
-classdir <compile-classes-directory> -impl -server -client -all
-autoNameResolution -defaultValues<=class name for DefaultValueProvider> -ant
-nexclude <schema namespace [= java packagename]>* -exsh <(true, false)>
-dns <(true, false)> -dex <(true, false)> -validate -keep
-wsdlLocation <wsdlLocation attribute> -xjc<xjc arguments> -noAddressBinding -h
-v -verbose -quiet <wsdlurl>
我们在命令行下输入:wsdl2java -p hs.cxf.client HelloWorld.wsdl 来指定生成的客户端包目录。
客户端调用代码
try {
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean ();
factory.setServiceClass(WebServiceSample.class);
factory.setAddress("http://127.0.0.1:9080/cxfTest/ws/HelloWorld");
Object obj = factory.create();
System.out.println(obj == null ? "NULL":obj.getClass().getName());
if(obj != null){
WebServiceSample ws = (WebServiceSample)obj;
String str = ws.say("test");
System.out.println(str);
str = ws.say("1111");
System.out.println(str);
User u = new User();
JAXBElement <String> je =
new JAXBElement <String>(
new QName("http://bean.cxf.hs","name"),
String.class,"张三");
u.setName(je);
str = ws.sayUserName(u);
System.out.println(str);
//通过对象来交互
ReqBean req = new ReqBean();
req.setExp(new JAXBElement <String>(
new QName("http://bean.cxf.hs","exp"),
String.class,"<exp>111<exp>"));
req.setSeqId(new JAXBElement <String>(
new QName("http://bean.cxf.hs","seqId"),
String.class,"12345678"));
RespBean resp = ws.action(req);
System.out.println("resp_id:"+resp.getRespId().getValue());
System.out.println("resp_exp:"+resp.getExp().getValue());
}
} catch (Exception ex) {
ex.printStackTrace();
}
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean ();
factory.setServiceClass(WebServiceSample.class);
factory.setAddress("http://127.0.0.1:9080/cxfTest/ws/HelloWorld");
Object obj = factory.create();
System.out.println(obj == null ? "NULL":obj.getClass().getName());
if(obj != null){
WebServiceSample ws = (WebServiceSample)obj;
String str = ws.say("test");
System.out.println(str);
str = ws.say("1111");
System.out.println(str);
User u = new User();
JAXBElement <String> je =
new JAXBElement <String>(
new QName("http://bean.cxf.hs","name"),
String.class,"张三");
u.setName(je);
str = ws.sayUserName(u);
System.out.println(str);
//通过对象来交互
ReqBean req = new ReqBean();
req.setExp(new JAXBElement <String>(
new QName("http://bean.cxf.hs","exp"),
String.class,"<exp>111<exp>"));
req.setSeqId(new JAXBElement <String>(
new QName("http://bean.cxf.hs","seqId"),
String.class,"12345678"));
RespBean resp = ws.action(req);
System.out.println("resp_id:"+resp.getRespId().getValue());
System.out.println("resp_exp:"+resp.getExp().getValue());
}
} catch (Exception ex) {
ex.printStackTrace();
}
运行此代码,查看结果即可
依赖包如下:
cxf-2.1.4.jar
jaxb-api-2.1.jar
geronimo-annotation_1.0_spec-1.1.1.jar
geronimo-ws-metadata_2.0_spec-1.1.2.jar
jaxws-api.jar
stax-api-1.0-2.jar
jaxb-impl-2.1.9.jar
geronimo-activation_1.1_spec-1.0.2.jar
xml-resolver-1.2.jar
XmlSchema-1.4.3.jar
wsdl4j-1.6.2.jar
saaj-api-1.3.jar
jsr173_1.0_ri.jar
jaxb-api-2.1.jar
geronimo-annotation_1.0_spec-1.1.1.jar
geronimo-ws-metadata_2.0_spec-1.1.2.jar
jaxws-api.jar
stax-api-1.0-2.jar
jaxb-impl-2.1.9.jar
geronimo-activation_1.1_spec-1.0.2.jar
xml-resolver-1.2.jar
XmlSchema-1.4.3.jar
wsdl4j-1.6.2.jar
saaj-api-1.3.jar
jsr173_1.0_ri.jar
其中jsr从bean下载:http://ftpna2.bea.com/pub/downloads/jsr173.jar (注意解压)
相关推荐
1. **库文件**:包含了CXF运行所需的JAR文件,如cxf-api.jar、cxf-rt-core.jar等,这些文件需要添加到项目的类路径中。 2. **文档**:可能包含API文档、用户指南和开发者手册,帮助开发者理解和使用CXF。 3. **示例*...
赠送jar包:cxf-rt-rs-client-3.0.1.jar; 赠送原API文档:cxf-rt-rs-client-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-rs-client-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-rs-client-3.0.1.pom; 包含...
CXF入门教程(2) -- 简单客户端示例文章附带代码,为使用方便,将service和client代码合并到一个工程中。原文地址http://blog.csdn.net/neareast/article/details/7717568
赠送jar包:cxf-rt-frontend-jaxrs-3.0.1.jar; 赠送原API文档:cxf-rt-frontend-jaxrs-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-frontend-jaxrs-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-frontend-jaxrs...
赠送jar包:cxf-rt-transports-http-3.0.1.jar; 赠送原API文档:cxf-rt-transports-http-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-transports-http-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-transports-...
赠送jar包:cxf-rt-frontend-simple-3.0.1.jar; 赠送原API文档:cxf-rt-frontend-simple-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-frontend-simple-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-frontend-...
赠送jar包:cxf-rt-frontend-jaxws-3.0.1.jar; 赠送原API文档:cxf-rt-frontend-jaxws-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-frontend-jaxws-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-frontend-jaxws...
赠送jar包:cxf-rt-bindings-soap-3.0.1.jar; 赠送原API文档:cxf-rt-bindings-soap-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-bindings-soap-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-bindings-soap-...
udp-3.0.11.jar,cxf-rt-wsdl-3.0.0.jar,cxf-rt-ws-security-3.0.0.jar,neethi-3.0.3.jar,slf4j-api-1.7.7.jar,stax2-api-3.1.4.jar,woodstox-core-asl-4.4.1.jar,wsdl4j-1.6.3.jar,wss4j-bindings-2.0.9.jar,xml...
赠送jar包:cxf-core-3.0.1.jar; 赠送原API文档:cxf-core-3.0.1-javadoc.jar; 赠送源代码:cxf-core-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-core-3.0.1.pom; 包含翻译后的API文档:cxf-core-3.0.1-...
而CXF-2可能指的是CXF的某个特定版本或更新,这可能包含新的特性和改进,对开发者来说,了解不同版本之间的差异和优化对于项目选择和升级至关重要。 在【压缩包子文件的文件名称列表】"cxf-2"中,我们可以推测这...
cxf-rt-frontend-jaxws-3.0.16.jar jar包下载3.0.16版本下载
赠送jar包:cxf-rt-rs-extension-providers-3.0.1.jar; 赠送原API文档:cxf-rt-rs-extension-providers-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-rs-extension-providers-3.0.1-sources.jar; 赠送Maven依赖信息...
赠送jar包:cxf-rt-databinding-jaxb-3.0.1.jar; 赠送原API文档:cxf-rt-databinding-jaxb-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-databinding-jaxb-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-...
赠送jar包:cxf-rt-bindings-xml-3.0.1.jar; 赠送原API文档:cxf-rt-bindings-xml-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-bindings-xml-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-bindings-xml-3.0.1....
赠送jar包:cxf-rt-ws-addr-3.0.1.jar; 赠送原API文档:cxf-rt-ws-addr-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-ws-addr-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-ws-addr-3.0.1.pom; 包含翻译后的API...
以下是如何使用maven-cxf-codegen-plugin生成客户端代码的步骤: 1. 在`pom.xml`中添加maven-cxf-codegen-plugin插件配置: ```xml <groupId>org.apache.cxf <artifactId>cxf-codegen-plugin ${cxf.version...
2. **客户端支持**:CXF不仅用于服务端,还允许开发者创建和使用Web服务客户端,与远程服务进行交互。 3. **协议支持**:CXF支持多种协议,包括HTTP、HTTPS、JMS等,而"rt-transports-http-jetty"部分就是对HTTP...
- **cxf-rt-transports-http.jar**和**cxf-rt-transports-http-hc.jar**:分别为HTTP和HTTP客户端的传输层实现。 - **cxf-rt-ws-security.jar**:包含WS-Security相关的类和接口。 此外,还有其他如`cxf-rt-...
<import resource="classpath:META-INF/cxf/cxf.xml"/> <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/> <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>