首页 技术 正文
技术 2022年11月21日
0 收藏 322 点赞 4,571 浏览 2950 个字

一、SOAP和WSDL概念:

  SOAP(Simple Object Access Protocol):简单对象访问协议

    SOAP作为一个基于XML语言的协议用于在网上传输数据

    SOAP=在Http的基础上+xml数据

    SOAP是基于http的

  WSDL(WebService Description Language):web 服务描述语言,就是一个xml文档,用于描述当前服务的一些信息(服务名称、服务的发布地址、服务提供的方法、方法的参数类型、方法的返回值类型等)。

二、apache CXF入门

    官网:cxf.apache.org下载CXF的开发包:

  服务端开发:

    第一步:创建动态web项目

    第二步:导入CXF相关jar包

    WebService-CXF使用

    第三步:在web.xml中配置CXF框架提供的一个Servlet 

 <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>crm</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list> <!-- CXF Servlet -->
<servlet>
<servlet-name>cxf</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet> <servlet-mapping>
<servlet-name>cxf</servlet-name>
<url-pattern>/service/*</url-pattern>
</servlet-mapping>
<!-- needed for ContextLoaderListener -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:cxf.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>

  第四步:在类路径下提供cxf.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:core="http://cxf.apache.org/core"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.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-3.2.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
<!-- 引入CXF Bean定义如下,早期的版本中使用 -->
<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" />
</beans>

    第五步:开发一个接口和实现类

  WebService-CXF使用

  WebService-CXF使用

    第六步:在cxf.xml中注册服务

WebService-CXF使用

  客户端开发

  第一步:创建Java项目并导入CXF相关jar包

  第二步:使用wsimport或者CXF提供wsdl2java生成本地代码,只需要生成接口文件

      wsdl2java 工具:此工具位于cxf_home/bin目录下,

      它包含以下参数:

        -d:指定代码生成的目录

        -p:指定生成的新的包结构

  WebService-CXF使用

  

    第三步:将接口文件复制到项目中

    WebService-CXF使用

    第四步:提供spring配置文件,注册客户端代理对象

    WebService-CXF使用 

    第五步:读取spring配置文件,创建spring工厂,从工厂中获取代理对象,实现远程调用

    WebService-CXF使用

    

  

    

下一篇: vim 安装
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,000
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,512
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,358
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,141
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,771
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,849