码迷,mamicode.com
首页 > 其他好文 > 详细

CXF实现服务端和客户端集成

时间:2016-04-22 19:13:54      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:

一、SEI的定义

假设有以下SEI定义:

Java代码 技术分享 技术分享技术分享
  1. @WebService  
  2. public interface OrderProcess {  
  3.     public String processOrder(Order order);  
  4. }  

 (实现端省略)

 

二、Server端发布

则最简单的发布Server的方式可以如下:

 

Java代码 技术分享 技术分享技术分享
  1. Endpoint.publish("http://localhost:8181/orderProcess"new OrderProcessImpl());  

 

或者是spring的方式:

Xml代码 技术分享 技术分享技术分享
  1. <beans xmlns="http://www.springframework.org/schema/beans"  
  2.     xmlns:jaxws="http://cxf.apache.org/jaxws"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"  
  4.     xsi:schemaLocation="  
  5.        http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd  
  6.        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  
  7.        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">  
  8.   
  9.     <import resource="classpath:META-INF/cxf/cxf.xml" />  
  10.     <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />  
  11.     <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />  
  12.   
  13.     <jaxws:endpoint id="orderProcess"  
  14.         implementor="com.liulutu.liugang.cxf.jaxws.OrderProcessImpl" address="http://localhost:8090/orderProcess" />  
  15. </beans>  

 三、Client端调用

Java代码 技术分享 技术分享技术分享
  1. Service service = Service.create(new URL("<wsdlfilepath>"),  
  2.         new QName("namespace""servicename"));  
  3. OrderProcess port = orderProcessService.getPort(OrderProcess.class);  
  4. String s = port.processOrder(<arg>);  
  5. System.out.println(s);  

 或者Spring的方式:

Xml代码 技术分享 技术分享技术分享
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.        xmlns:jaxws="http://cxf.apache.org/jaxws"  
  4.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  5.        xsi:schemaLocation="  
  6.           http://www.springframework.org/schema/beans   
  7.           http://www.springframework.org/schema/beans/spring-beans.xsd  
  8.           http://cxf.apache.org/jaxws   
  9.           http://cxf.apache.org/schemas/jaxws.xsd">  
  10.    
  11.     <jaxws:client id="orderClient"  
  12.                   serviceClass="com.liulutu.liugang.cxf.codefirst.OrderProcess"  
  13.                   address="http://localhost:8181/orderProcess" />  
  14. </beans>  

 然后在Java代码里:

Java代码 技术分享 技术分享技术分享
  1. ClassPathXmlApplicationContext xmlApplicationContext = new ClassPathXmlApplicationContext(  
  2.       "/META-INF/spring/jaxwsspringclient.xml");  
  3. OrderProcess bean = xmlApplicationContext.getBean(OrderProcess.class);  
  4. System.out.println(bean.processOrder(<order>));  

CXF实现服务端和客户端集成

标签:

原文地址:http://blog.csdn.net/yanyu529584640/article/details/51220633

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!