[CXF] Server与Client实现方式二:Simple

【参考:http://cxf.apache.org/docs/jax-ws-configuration.html

【参考:http://cxf.apache.org/docs/writing-a-service-with-spring.html

【参考:http://cxf.apache.org/docs/simple-frontend-configuration.html

上节里,我们介绍了JAX-WS的创建Service和调用Service的方式。这节介绍另种实现方式:Simple。

 

除了支持通过读取jax-ws的annotation来生成webservice,CXF也支持直接从一个类对象生成webservice服务,这就是这里要介绍的simple frontend方式。

 

一、Service接口定义

public interface OrderProcess {

	String processOrder(Order order);
	
}

 

没有任何jax-ws相关的annotation

二、Server的发布

        ServerFactoryBean bean = new ServerFactoryBean();
        bean.setAddress("http://localhost:8181/cxf/simple");
        bean.setServiceBean(new OrderProcessImpl());
        bean.setServiceClass(OrderProcess.class);
        bean.create();

 或者是Spring方式:

<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:simple="http://cxf.apache.org/simple"
	xmlns:soap="http://cxf.apache.org/bindings/soap"
	xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd
http://cxf.apache.org/simple http://cxf.apache.org/schemas/simple.xsd">

	<simple:server id="orderProcess"
		serviceClass="com.liulutu.liugang.cxf.simple.OrderProcess" address="http://localhost:8181/cxf/simple">
		<simple:serviceBean>
			<bean class="com.liulutu.liugang.cxf.simple.OrderProcessImpl" />
		</simple:serviceBean>
	</simple:server>
</beans>

  三、Client端的实现

        ClientProxyFactoryBean client = new ClientProxyFactoryBean();

        client.setAddress("http://localhost:8181/cxf/simple");
        client.setServiceClass(OrderProcess.class);
        OrderProcess orderProcess = (OrderProcess)client.create();
        String s = orderProcess.processOrder(<order>);
        System.out.println(s);

 

或者是Spring的方式:

<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:simple="http://cxf.apache.org/simple"
	xmlns:soap="http://cxf.apache.org/bindings/soap"
	xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd
http://cxf.apache.org/simple http://cxf.apache.org/schemas/simple.xsd">

	<simple:client id="orderClient"
		serviceClass="com.liulutu.liugang.cxf.simple.OrderProcess" address="http://localhost:8181/cxf/simple">
	</simple:client>
</beans>

 

然后在java代码里:

    	ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("/com/liulutu/liugang/cxf/simple/client.xml");
    	OrderProcess bean = context.getBean("orderClient", OrderProcess.class);
        String processOrder = bean.processOrder(<order>);
        System.out.println(processOrder);

 

你可能感兴趣的:(server)