SOAP 1.1与1.2版本区别

来源:互联网 发布:网络诈骗 刑事立案 编辑:程序博客网 时间:2024/05/16 08:27

转自:http://blog.sina.com.cn/s/blog_5f044a4d0101gzli.html

WebService通过HTTP协议完成远程调用: (深入分析)  RPC 

lWebService只采用HTTP POST方式传输数据,不使用GET方式;  -- 握手,WSDL-get,
普通http postcontentType
application/x-www-form-urlencoded
WebServicecontentType为-即在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.1SOAP1.2 namespace不一样。可以通过查看类
javax.xml.ws.soap.SOAPBinding来查看里面的常量
默认情况下,Jdk1.6只支持soap1.1
即:@BindingType(value=javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING)
 
SOAP提升:
 
1.目前WebService的协议主要有SOAP1.11.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.1content-Type:text/xm;charset=UTF-8
2.1.2content-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.1HTTP请求头:

 

      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.11.2WSDL文件的差别:

 

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:soapBindingversion="1.2" />
  </</FONT>jaxws:binding>
SOAP 1.1 request: 

POST /WSShakespeare.asmx HTTP/1.1 
Host: www.xmlme.com 
Content-Type: text/xml; charset=utf-8 
Content-Length: length 
SOAPAction: "http://xmlme.com/WebServices/GetSpeech" 

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
  <soap:Body> 
    <GetSpeech xmlns="http://xmlme.com/WebServices"> 
      <Request>string</Request> 
    </GetSpeech> 
  </soap:Body> 
</soap:Envelope> 


SOAP 1.2 request: 

POST /WSShakespeare.asmx HTTP/1.1 
Host: www.xmlme.com 
Content-Type: application/soap+xml; charset=utf-8 
Content-Length: length 

<?xml version="1.0" encoding="utf-8"?> 
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
  xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> 
  <soap12:Body> 
    <GetSpeech xmlns="http://xmlme.com/WebServices"> 
      <Request>string</Request> 
    </GetSpeech> 
  </soap12:Body> 
</soap12:Envelope> 
I see 3 differences: 
SOAP 1.2 uses "application/soap+xml" as Content-Type and SOAP 1.1 uses "text/xml". 
SOAP 1.2 does not use SOAPAction header line. 
SOAP 1.2 uses "http://www.w3.org/2003/05/soap-envelope" as the envolope namespace and SOAP 1.1 uses "http://schemas.xmlsoap.org/soap/envelope/" 
0 0
原创粉丝点击