赞
踩
不同系统,不同平台,不同语言之间的通信访问和调用
应用程序的集成,不同业务的整合(异构系统之间的访问和调用)
WebService的定义/什么是WebService
WebService运行与访问过程
WebService核心组件
Web服务一种服务导向架构的技术,通过标准的Web协议提供服务,目的是保证不同平台的应用服务可以互操作.
表面上看WebService就是一个应用程序,它向外界暴露一个能够通过Web进行调用的方法API,能用编程的方法通过Web调用来实现某个功能的应用程序.
深层次上看WebService是一种新的Web应用程序分支,它们是包含, 自描述模块化的应用, 可以在网络中被描述, 发布 , 查找以及通过Web来调用.
什么是java的多态? 父类的引用指向子类的实例
CXF下载:http://cxf.apache.org/download.html
*Linux下 .tar.gz文件解压缩命令
1、压缩命令:
命令格式:tar -zcvf 文件名 -------文件名.tar.gz 被压缩后的文件名
可先切换到当前目录下。压缩文件名和被压缩文件名都可加入路径。
2.解压缩命令:
命令格式:tar -zxvf 文件名.tar.gz
解压缩后的文件只能放在当前的目录。
结论:SOAP是用于访问网络服务的协议
一次WebService的调用,不是方法的调用
而是
soap消息(xml格式规范的文档片段)之间的输入输出
安装Axis TCP Monitor Plugin
打开TCPMON
启动监听端口调用客户端访问
<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://cxf.atchinasoft.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" name="HelloWorldServiceImplService" targetNamespace="http://cxf.atchinasoft.com/"> <wsdl:types> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://cxf.atchinasoft.com/" elementFormDefault="unqualified" targetNamespace="http://cxf.atchinasoft.com/" version="1.0">...</xs:schema> </wsdl:types> <wsdl:message name="sayHello"> <wsdl:part element="tns:sayHello" name="parameters"> </wsdl:part> </wsdl:message> <wsdl:message name="sayHelloResponse"> <wsdl:part element="tns:sayHelloResponse" name="parameters"> </wsdl:part> </wsdl:message> <wsdl:portType name="Helloworld"> <wsdl:operation name="sayHello"> <wsdl:input message="tns:sayHello" name="sayHello"> </wsdl:input> <wsdl:output message="tns:sayHelloResponse" name="sayHelloResponse"> </wsdl:output> </wsdl:operation> </wsdl:portType> <wsdl:binding name="HelloWorldServiceImplServiceSoapBinding" type="tns:Helloworld"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="sayHello"> <soap:operation soapAction="" style="document"/> <wsdl:input name="sayHello">...</wsdl:input> <wsdl:output name="sayHelloResponse">...</wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="HelloWorldServiceImplService"> <wsdl:port binding="tns:HelloWorldServiceImplServiceSoapBinding" name="HelloWorldServiceImplPort"> <soap:address location="http://127.0.0.1/cxf1022_server"/> </wsdl:port> </wsdl:service> </wsdl:definitions>
definitions: 命名空间: 根元素
types: webservice使用的数据
message: webservice使用的消息
binding: webservice使用的通信协议
service:webservice对外暴露
<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://cxf.atchinasoft.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:ns1="http://schemas.xmlsoap.org/soap/http" name="HelloWorldServiceImplService"
targetNamespace="http://cxf.atchinasoft.com/">
</wsdl:definitions>
xmllns | 相当于Java里面的import, 包名反转 |
name | 我们java程序中服务接口的实现类,SEI定义是:服务接口类+Service后缀, Service自动追加. |
targetNamespace | 命名空间: 相当于Java里面的package它刚好是和我们Java定义的包名相反. |
其他 | 不变化,不关心 |
通信消息的数据结构的抽象类型化定义,使用Types所定义的类型来定义整个消息的数据结构
<wsdl:message name="sayHello">
<wsdl:part element="tns:sayHello" name="parameters"> </wsdl:part>
</wsdl:message>
<wsdl:message name="sayHelloResponse">
<wsdl:part element="tns:sayHelloResponse" name="parameters"> </wsdl:part>
</wsdl:message>
WebService中每个方法包含两部分:
<wsdl:portType name="Helloworld">
<wsdl:operation name="sayHello">
<wsdl:input message="tns:sayHello" name="sayHello"> </wsdl:input>
<wsdl:output message="tns:sayHelloResponse" name="sayHelloResponse"> </wsdl:output>
</wsdl:operation>
</wsdl:portType>
portType = 接口
operation = 接口中定义的方法
特定端口类型的具体协议和数据格式规范
<wsdl:binding name="HelloWorldServiceImplServiceSoapBinding" type="tns:Helloworld">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="sayHello">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="sayHello">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="sayHelloResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
负责将网络通信地址赋给一个具体的绑定
<wsdl:service name="HelloWorldServiceImplService">
<wsdl:port binding="tns:HelloWorldServiceImplServiceSoapBinding" name="HelloWorldServiceImplPort">
<soap:address location="http://127.0.0.1/cxf1022_server"/>
</wsdl:port>
</wsdl:service>
JAXB = Java API For XML Binding
JAXB是Java Architecture for XML Binding的缩写,提供了一个快捷的方式将Java对象与XML进行转换.
在JAX-WS(Java的WebService规范之一)中, JDK1.6之后自带的版本JAX-WS2.1, 其底层支持就是JAXB.
JAXB可以实现POJO对象和XML之间相互转换
Unmarshaller类将XML数据反序列化为新创建的Java内容树的进程,并可在解组时有选择的验证XML数据.
Marshaller类将Java内容树序列化回XML数据的过程
package com.atchinasoft.cxf; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import lombok.experimental.Accessors; /** * @author xianyiquan * @className * @create 2019-11-20 23:44 */ @AllArgsConstructor @NoArgsConstructor @Data @Accessors(chain=true) public class Book { private long id; private String bookName; private double price; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。