WebService通过HTTP协议完成远程调用:
(深入分析)
–
RPC
lWebService只采用HTTP
POST方式传输数据,不使用GET方式;
--
握手,WSDL-get,
•普通http
post的contentType为
•application/x-www-form-urlencoded
•WebService的contentType为-即在Http的基础上发SOAP协议
•text/xml
这是基于soap1.1协议。
•application/soap+xml
这是基于soap1.2协议。
lWebService从数据传输格式上作了限定。WebService所使用的数据均是基于XML格式的。目前标准的WebService在数据格式上主要采用SOAP协议。SOAP协议实际上就是一种基于XML编码规范的文本协议。
lSOAP
– Simple Object Access protocol
简单对像访问协议。是运行在HTTP协议基础之上的协议。其实就是在HTTP协议是传输XML文件,就变成了SOAP协议。
lSOAP1.1和SOAP1.2的
namespace不一样。可以通过查看类
•javax.xml.ws.soap.SOAPBinding来查看里面的常量
•默认情况下,Jdk1.6只支持soap1.1
•即:@BindingType(value=javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING)
SOAP提升:
1.目前WebService的协议主要有SOAP1.1和1.2。
2.两者的命名空间不同。
1.见下页对比。
3.SOAP1.1版本与SOAP1.2版本在头信息上存在差异。
1.SOAP1.1存在SOAPAction的请求头。
2.SOAP1.2没有SOAPAction的请求头。
4.基于SOAP1.1生成的WSDL和基于SOAP1.2生成的WSDL也不一样。
1.主要看命名空间。
5.在CXF中两种协议请求的方式也不一样。
1.1.1为content-Type:text/xm;charset=UTF-8
2.1.2为content-Type:application/soap+xml;charset=UTF-8
命名空间:
Soap1.1的命名空间:
xmlns:soap=“http://schemas.xmlsoap.org/soap/envelope/
“
Soap1.2
命名空间:
xmlns:soap="http://www.w3.org/2003/05/soap-envelope“
SOAP1.1的HTTP请求头:
POST /xe_cxf2.4_soap12_spring_web/ws/helloworldsoap12?wsdl
HTTP/1.1
Content-Type:
text/xml;
charset=UTF-8
Accept: **
User-Agent: Apache CXF 2.4.0
Cache-Control: no-cache
Pragma:
no-cache
Host: localhost:6767
Connection: keep-alive
Content-Length: 214
SOAP1.2的请求头:
POST /xe_cxf2.4_soap12_spring_web/ws/helloworldsoap12?wsdl
HTTP/1.1
Content-Type:
application/soap+xml;
charset=UTF-8
Accept:
*/*
User-Agent: Apache CXF 2.4.0
Cache-Control: no-cache
Pragma:
no-cache
Host: localhost:6767
Connection: keep-alive
Content-Length: 214
SOAP1.1和1.2的WSDL文件的差别:
l在定义Service部分差别如下:
lSoap1.1是以:soap:address定义。
lSoap1.2是以:
soap12:address定义。-jdk1.6不支持12形式的访问。
通过BindingType将项目转到1.2
l在类上面添加以下注解可以使用soap1.2的协议:
•@BindingType(value=SOAPBinding.SOAP12HTTP_BINDING)
l或在applicationContext.xml中使用binding
•<</SPAN>jaxws:binding>
•
<</FONT>soap:soapBinding
version="1.2" />
•
</</FONT>jaxws:binding>
加载中,请稍候......