参考链接:http://cxf.apache.org/docs/writing-a-service-with-spring.html
先说下cxf是什么东西吧:
Apache CXF 是一个开源的 Services 框架,CXF 帮助您利用 Frontend 编程 API 来构建和开发 Services ,像 JAX-WS 。这些 Services 可以支持多种协议,比如:SOAP、XML/HTTP、RESTful HTTP 或者 CORBA ,并且可以在多种传输协议上运行,比如:HTTP、JMS 或者 JBI,CXF 大大简化了 Services 的创建,同时它继承了 XFire 传统,一样可以天然地和 Spring 进行无缝集成。
?
一、SEI的定义
假设有以下SEI定义:
- @WebService??
- public?interface?OrderProcess?{??
- ????public?String?processOrder(Order?order);??
- }??
?(实现端省略)
?
二、Server端发布
则最简单的发布Server的方式可以如下:
?
- Endpoint.publish("http://localhost:8181/orderProcess",?new?OrderProcessImpl());??
?
或者是spring的方式:
- <beans?xmlns="http://www.springframework.org/schema/beans"??
- ????xmlns:jaxws="http://cxf.apache.org/jaxws"??
- ????xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"?xmlns:context="http://www.springframework.org/schema/context"??
- ????xsi:schemaLocation="??
- ???????http://cxf.apache.org/jaxws?http://cxf.apache.org/schemas/jaxws.xsd??
- ???????http://www.springframework.org/schema/beans?http://www.springframework.org/schema/beans/spring-beans.xsd??
- ???????http://www.springframework.org/schema/context?http://www.springframework.org/schema/context/spring-context.xsd">??
- ??
- ????<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"?/>??
- ??
- ????<jaxws:endpoint?id="orderProcess"??
- ????????implementor="com.liulutu.liugang.cxf.jaxws.OrderProcessImpl"?address="http://localhost:8090/orderProcess"?/>??
- </beans>??
?三、Client端调用
- Service?service?=?Service.create(new?URL("<wsdlfilepath>"),??
- ????????new?QName("namespace",?"servicename"));??
- OrderProcess?port?=?orderProcessService.getPort(OrderProcess.class);??
- String?s?=?port.processOrder(<arg>);??
- System.out.println(s);??
?或者Spring的方式:
- <?xml?version="1.0"?encoding="UTF-8"?>??
- <beans?xmlns="http://www.springframework.org/schema/beans"??
- ???????xmlns:jaxws="http://cxf.apache.org/jaxws"??
- ???????xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"??
- ???????xsi:schemaLocation="??
- ??????????http://www.springframework.org/schema/beans???
- ??????????http://www.springframework.org/schema/beans/spring-beans.xsd??
- ??????????http://cxf.apache.org/jaxws???
- ??????????http://cxf.apache.org/schemas/jaxws.xsd">??
- ???
- ????<jaxws:client?id="orderClient"??
- ??????????????????serviceClass="com.liulutu.liugang.cxf.codefirst.OrderProcess"??
- ??????????????????address="http://localhost:8181/orderProcess"?/>??
- </beans>??
?然后在java代码里:
- ClassPathXmlApplicationContext?xmlApplicationContext?=?new?ClassPathXmlApplicationContext(??
- ??????"/META-INF/spring/jaxwsspringclient.xml");??
- OrderProcess?bean?=?xmlApplicationContext.getBean(OrderProcess.class);??
- System.out.println(bean.processOrder(<order>));?