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

一、SEI的定义

假设有以下SEI定义:

Java代码  

  1. @WebService
  2. public interface OrderProcess {
  3. public String processOrder(Order order);
  4. }
@WebService
public interface OrderProcess {
    public String processOrder(Order order);
}

(实现端省略)

二、Server端发布

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

Java代码  

  1. Endpoint.publish("http://localhost:8181/orderProcess", new OrderProcessImpl());
        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. <import resource="classpath:META-INF/cxf/cxf.xml" />
  9. <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
  10. <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
  11. <jaxws:endpoint id="orderProcess"
  12. implementor="com.liulutu.liugang.cxf.jaxws.OrderProcessImpl" address="http://localhost:8090/orderProcess" />
  13. </beans>
<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端调用

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);
        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代码  

  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. <jaxws:client id="orderClient"
  11. serviceClass="com.liulutu.liugang.cxf.codefirst.OrderProcess"
  12. address="http://localhost:8181/orderProcess" />
  13. </beans>
<?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代码里:

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>));
时间: 2024-08-30 14:38:56

CXF实现服务端和客户端集成的相关文章

CXF WebService服务端成功(集成spring)

原文出自:http://blog.csdn.net/xuanjie25/article/details/7686118 http://liuzl121.iteye.com/blog/1733969 http://blog.sina.com.cn/s/blog_8ee5914d01016ctl.html 搭建webservice 由于做项目需要写一个手机客户端访问之前做好的项目,所以需要了解Apache CXF服务框架,调试了很久才把服务端跟测试的弄好,写下来免得以后忘记了 首先建一个web se

使用Apache CXF开发WebServices服务端、客户端

在前一篇的博客中,我使用Xfire1.x来开发了WebServies的服务端. 但是如果你访问Apache的官网,可以看到xfire已经被合并了. 最新的框架叫做CXF. Apache CXF = Celtix + XFire. CXF 继承了 Celtix 和 XFire 两大开源项目的精华, 提供了对 JAX-WS 全面的支持,并且提供了多种 Binding .DataBinding.Transport 以及各种 Format 的支持,并且可以根据实际项目的需要,采用代码优先(Code Fi

spring + cxf 的webservice服务端和客户端功能

原文:spring + cxf 的webservice服务端和客户端功能 源代码下载地址:http://www.zuidaima.com/share/1550463730928640.htm spring + cxf 的webservice服务端和客户端功能. 提供页面调用ws和java代码调用两种方式. 引用jar包请下载:http://pan.baidu.com/s/1jGog2WI

mvn构建JAX-WS项目含服务端和客户端代码实现

java中WebService框架有很多,像Axis,XFire,CXF等,除了上述框架外,JDK中自带JAX-WS框架.相比而言,JWS是轻量级的,使用非常简便,可与Spring集成使用. 下面就详述如何通过mvn构建WebService服务端及客户端. 1.引包. 在mvn项目的pom文件中加入依赖包 <dependency> <groupId>com.sun.xml.ws</groupId> <artifactId>jaxws-rt</artif

grpc(3):使用 golang 开发 grpc 服务端和客户端

1,关于grpc-go golang 可以可以做grpc的服务端和客户端. 官网的文档: http://www.grpc.io/docs/quickstart/go.html https://github.com/grpc/grpc-go 和之前写的java的grpc客户端调用相同.也需要使用protobuf的配置文件. 但是golang下面的类库非常的简单,而且golang的性能也很强悍呢. 有些简单的业务逻辑真的可以使用golang进行开发. 性能强悍而且,消耗的资源也很小.java感觉上已

关于ntp(时间同步协议)服务端和客户端的配置说明

本文主要写了一些在Linux(CentOS)服务器上配置ntp的经验,事件缘由来源于配置Zabbix监控ntp服务时的测试配置. NTP时间同步协议的服务端(ntpd服务)和客户端(ntpdate服)不能同时运行,即在运行ntpd服务后不能运行ntpdate服务,否则ntpdate服务会提示启动失败,而且日志中也会提示"the NTP socket is in use, exiting",如下图所示. 但客户端运行时,服务端可以运行,但服务端运行时,客户端不能运行,要运行客户端服务,就

socket服务端和客户端

#!/usr/bin/env python#encoding: utf-8import socketdef handle_request(client): buf = client.recv(1024) client.send("HTTP/1.1 200 OK\r\n\r\n") client.send("Hello, World") def main(): sock = socket.socket(socket.AF_INET, socket.SOCK_STREA

用Java实现HTTP Multipart的服务端和客户端

今天简单介绍一下如何用Java支持HTTP Multipart的request和response. 整个项目的代码可以在https://github.com/mcai4gl2/multi下载. 在这个程序里,我们的业务场景很简单.在服务端有一个随机数生成器,可以生成随机的Integer和Guid,客户端通过服务,可以请求一个或多个随机数.同时,客户端可以向服务端发送一个或多个随机数,这些随机数会被加入到一个队列中,被其他的客户端通过请求获得.以下是我们的随机数Bean的定义: [java] vi

C# Socket服务端和客户端互相send和receive

服务端 1 using System; 2 using System.Collections.Generic; 3 using System.Text; 4 using System.Net.Sockets; 5 using System.Net; 6 using System.Threading; 7  8 namespace Controller 9 {10     public static class SocketServer11     {12         private stat