SOAP提升:
命名空间:
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?wsdlHTTP/1.1
Content-Type:text/xml; charset=UTF-8
Accept: */*
SOAPAction:""
User-Agent:Apache CXF 2.4.0
Cache-Control: no-cache
Pragma: no-cache
Host: localhost:6767
Connection: keep-alive
Content-Length: 216
注意上面包含SOAPAction且请求方式为text/xml。
SOAP1.2的请求头:
POST /xe_cxf2.4_soap12_spring_web/ws/helloworldsoap12?wsdlHTTP/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
注意上面没有SOAPAction且类型为soap+xml.
SOAP1.1和1.2的WSDL文件的差别:
通过BindingType将项目转到1.2:
SOAP1.2的调用:
SOAP11与SOAP12的调用关系:
CXF中两种协议请求的方式也不一样
Soap1.1以普通方式访问:
使用JaxWsProxyFactoryBean
Soap1.2以指定wsdl地址和命名空间的形式访问:
Service service = Service.create(newURL(“wsdlUrl”),
new QName(“namespace”,”ServiceName”));
SomeClass sc = service.getPort(new QName(“namespace”,”PortName”),
SomeClass.class);
sc.someMethod(someParam);
通过Ajax形式访问:
1、指定contentType:’application/soap+xml;charset=“UTF-8”‘
2、组织使用XML数据,使用SOAP12的命名空间.
var str = '<soap12:Envelope xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">'+
'<soap12:Body><ns2:sayHi xmlns:ns2="http://service.itcast.com/">'+
'<arg0>'+nm+'</arg0></ns2:sayHi></soap12:Body></soap12:Envelope>';
$.ajax({
url:'<c:url value="/ws/greeting"/>',
contentType:'application/soap+xml;charset="UTF-8"',
dataType:'xml',
type:'post',
data:str,
success:function(data){
var vv = $(data).find("return").eq(0).text();
$("<div>").text(vv).css({border:'1px solid red',width:'500px',marginTop:'5px'})
.appendTo($("body"));
}
},"xml");