【参考:http://cxf.apache.org/docs/jax-ws-configuration.html】
一、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>));