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

本文介绍如何使用CXF的Simple方式创建Webservice接口、发布服务和实现客户端调用,包括使用Java类直接生成Webservice及Spring配置方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

【参考: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);

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值