1.什么是webservice
2.为什么要使用webservice
3.什么时候要去使用webservice
4.webservice中的一些概念
5.SOAP(simple object access protocal简单对象访问协议)
6.SEI(webservice endpoint interface webservice的终端接口)
7.开发一个webservice的实例
8.分析WSDL文档
9.实现webservice的技术
10.spring+cxf+REST实现webservice
11.参考
1.什么是webservice
webservice也可以叫xml web service webservice, 轻量级的独立的通讯技术
1)基于web的服务:服务端提供的服务接口让客户端访问
2)跨平台、跨语言的整合方案
2.为什么要使用webservice
跨语言调用的解决方案
3.什么时候要去使用webservice
电商平台,订单的物流状态。
.net实现的webservice服务接口
4.webservice中的一些概念
WSDL(web service definition language webservice 定义语言)
webservice服务需要通过wsdl文件来说明自己有什么服务可以对外调用。并且有哪些方法、方法里面有哪些参数
wsdl基于XML(可扩展标记语言)去定义的
- 对应一个.wsdl的文件类型
- 定义了webservice的服务器端和客户端应用进行交互的传递数据和响应数据格式和方式
- 一个webservice对应唯一一个wsdl文档
5.SOAP(simple object access protocal简单对象访问协议)
http+xml
webservice通过http协议发送和接收请求时, 发送的内容(请求报文)和接收的内容(响应报文)都是采用xml格式进行封装
这些特定的HTTP消息头和XML内容格式就是SOAP协议
1.一种简单、基于HTTP和XML的协议
2.soap消息:请求和响应消息
3.http+xml报文
6.SEI(webservice endpoint interface webservice的终端接口)
webservice服务端用来处理请求的接口,也就是发布出去的接口。
7.开发一个webservice的实例
查看源码
到jdk的bin目录生成客户端代码
wsimport -keep http://localhost:8080/charjay/hello?wsdl
8.分析WSDL文档
<types>
<xsd:schema>
<xsd:import namespace="http://webservice.charjay.com/" schemaLocation="http://localhost:8080/charjay/hello?xsd=1"/>
</xsd:schema>
</types>
<message name="sayHello">
<part name="parameters" element="tns:sayHello"/>
</message>
<message name="sayHelloResponse">
<part name="parameters" element="tns:sayHelloResponse"/>
</message>
<portType name="SayHelloImpl">
<operation name="sayHello">
<input wsam:Action="http://webservice.charjay.com/SayHelloImpl/sayHelloRequest" message="tns:sayHello"/>
<output wsam:Action="http://webservice.charjay.com/SayHelloImpl/sayHelloResponse" message="tns:sayHelloResponse"/>
</operation>
</portType>
<binding name="SayHelloImplPortBinding" type="tns:SayHelloImpl">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="sayHello">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="SayHelloImplService">
<port name="SayHelloImplPort" binding="tns:SayHelloImplPortBinding">
<soap:address location="http://localhost:8080/charjay/hello"/>
</port>
</service>
1)Types标签
定义整服务端的数据报文
2)Schema标签
http://localhost:8080/vip/hello?xsd=1
<xs:schema xmlns:tns="http://webservice.charjay.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0" targetNamespace="http://webservice.charjay.com/">
<xs:element name="sayHello" type="tns:sayHello"/>
<xs:element name="sayHelloResponse" type="tns:sayHelloResponse"/>
<xs:complexType name="sayHello">
<xs:sequence>
<xs:element name="arg0" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="sayHelloResponse">
<xs:sequence>
<xs:element name="return" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
大概的报文(请求)
<sayHello>
<arg0>String</arg0>
</sayHello>
实际报文
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webservice.mic.vip.gupao.com/">
<soapenv:Header/>
<soapenv:Body>
<web:sayHello>
<!--Optional:-->
<arg0>?</arg0>
</web:sayHello>
</soapenv:Body>
</soapenv:Envelope>
大概的报文(返回)
<sayHelloResponse>
<return>string</return>
</sayHelloResponse>
实际报文
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:sayHelloResponse xmlns:ns2="http://webservice.mic.vip.gupao.com/">
<return>Hello ,Mic,I'am 菲菲</return>
</ns2:sayHelloResponse>
</S:Body>
</S:Envelope>
3)Message
定义了在通信中使用的消息的数据结构
4)PortType
定义服务器端的SEI
input/output表示输入/输出数据
5)Binding标签
1.type属性: 引用porttype
绑定的数据类型是文档
2.operation : 指定实现方法
3.input/output 表示输入和输出的数据类型
6)Service标签
service: 服务器端的一个webservice的容器
name属性: 指定客户端的容器类
address: 当前webservice的请求地址
指向图
请求过程,发送的报文与返回的报文
9.实现webservice的技术
Axis/Axis2(apache开源的webservice工具,可以生成多种语言的客户端)
Celtix+Xfire ( 用的很广泛,因为集成到了spring)
CXF(很少用)
Xfire(早期的高性能的Webservice)
HTTP+JSON (新的webservice)
10.spring+cxf+REST实现webservice
核心实现
(1)web.xml配置 org.apache.cxf.transport.servlet.CXFServlet
(2)spring配置 jaxrs:server
(3)注解
@DELETE、@GET、@POST、@PUT
@Path("{id}") //http://ip:port/users/1
@Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) //请求accept
code:https://blog.csdn.net/charjay_lin/article/details/80948427
11.参考
http://my.oschina.net/u/1757458/blog/365588
http://www.cnblogs.com/adolfmc/p/4383091.html