Angelo Lee's Blog
This is my kingdom .If i don't fight for it ,who will ?

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

WebService只采用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协议。

WebService从数据传输格式上作了限定。WebService所使用的数据均是基于XML格式的。目前标准的WebService在数据格式上主要采用SOAP协议。SOAP协议实际上就是一种基于XML编码规范的文本协议。

SOAP – Simple Object Access protocol 简单对像访问协议。是运行在HTTP协议基础之上的协议。其实就是在HTTP协议是传输XML文件,就变成了SOAP协议。目前SOAP的版本主要有SOAP1.1和SOAP1.2。

SOAP1.1和SOAP1.2的namespace不一样。

Soap1.1命名空间:

xmlns:soap=“http://schemas.xmlsoap.org/soap/envelope/“

Soap1.2 命名空间:

xmlns:soap="http://www.w3.org/2003/05/soap-envelope

可以通过查看类

•javax.xml.ws.soap.SOAPBinding来查看里面的常量

•默认情况下,Jdk1.6只支持soap1.1

•即:@BindingType(value=javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING)

jdk1.6默认不支持12形式的访问。SOAP提升:

通过BindingType将项目转到1.2

在类上面添加以下注解可以使用soap1.2的协议:

•@BindingType(value=SOAPBinding.SOAP12HTTP_BINDING)

或在applicationContext.xml中使用binding

•<</SPAN>jaxws:binding>

• <</FONT>soap:soapBindingversion="1.2" />

• </</FONT>jaxws:binding>

3.SOAP1.1版本与SOAP1.2版本在头信息上存在差异。

1.SOAP1.1存在SOAPAction的请求头。

2.SOAP1.2没有SOAPAction的请求头。

4.SOAP1.1和1.2的WSDL文件的差别:

1.主要看命名空间。

2.在定义Service部分差别如下:

Soap1.1是以:soap:address定义。

Soap1.2是以: soap12:address定义。-jdk1.6不支持12形式的访问。

5.在CXF中两种协议请求的方式也不一样。

1.SOAP1.1为content-Type:text/xm;charset=UTF-8

2.SOAP1.2为content-Type:application/soap+xml;charset=UTF-8

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 request and SOAP1.2 request:

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>

SOAP1.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>

Differences between SOAP1.1 and  SOAP1.2:

  • 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/”
    posted on 2014-12-21 17:03  Angelo Lee  阅读(3796)  评论(0编辑  收藏  举报