基于SOAP的Web服务AJAX客户端
2015年12月14日
2015年12月15日添加WSDL
2015-12-16 添加SOAP与JSON转换
参考:http://www.myexception.cn/h/1158587.html
参见:Java-webservice-CXF-SOAP服务.docx流程。
注意:html文件放在WebContent根目录(保证处于同一域)。
参考:http://www.tuicool.com/articles/iueYNj
//index.html
<!DOCTYPE html>
<html>
<head>
<metacharset="UTF-8">
<title>Insert titlehere</title>
</head>
<scripttype="text/javascript"src="jquery-1.11.3.js"></script>
<body>
<buttontype="button" id="name">Web服务请求-SOAP</button >
<script type="text/javascript">
$(function() {
$("#name").click(function(){
var url = "/CXFSoapDemo/services/HelloWorld";
var soap = '<soapenv:Envelopexmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" '+
'xmlns:xsd="http://www.w3.org/2001/XMLSchema"'+
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'+
'<soapenv:Bodyxmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://lee/"><tns:sayHello/></soapenv:Body></soapenv:Envelope>';
$.ajax({
url : url,//访问的url
dataType : 'xml',//返回的数据类型
type : 'post',//请求方式
contentType :'application/soap+xml;charset=UTF-8',
data : soap,//数据
success : function(data,status,
xhr) {
//对返回后的数据进行解析
$(data).find("return").each(
function(index,item) {
console.debug(item.innerHTML)
console.debug($(this));
});
},
error : function(xhr, status){
alert("出错了:" +status);
}
});
});
});
</script>
</body>
</html>
点击页面,获取服务取返回结果。
参考:http://www.myexception.cn/web/677069.html
//example.xml
<soap:Envelopexmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body xmlns:tns="http://lee/" >
<tns:sayHello/>
</soap:Body>
</soap:Envelope>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body xmlns:tns="http://lee/" >
<tns:sayHello/>
</soap:Body>
Envelope:必须,使用http://schemas.xmlsoap.org/soap/envelope/定义
-|Header:可选
-|Body:必须,定义ws的命名空间
--|消息内容:必须,定义ws定义的方法。
-|Fault:可选。
This XML file does not appearto have any style information associated with it. The document tree is shownbelow.
<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://lee/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"xmlns:ns1="http://schemas.xmlsoap.org/soap/http" name="HelloWorldImplService" targetNamespace="http://lee/">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://lee/" elementFormDefault="unqualified" targetNamespace="http://lee/" version="1.0">
<xs:element name="say" type="tns:say"/>
<xs:element name="sayHello" type="tns:sayHello"/>
<xs:element name="sayHelloResponse" type="tns:sayHelloResponse"/>
<xs:element name="sayResponse" type="tns:sayResponse"/>
<xs:complexType name="sayHello">
<xs:sequence/>
</xs:complexType>
<xs:complexType name="sayHelloResponse">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="say">
<xs:sequence>
<xs:element minOccurs="0" name="arg0" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="sayResponse">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="sayResponse">
<wsdl:part element="tns:sayResponse" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="say">
<wsdl:part element="tns:say" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="sayHelloResponse">
<wsdl:part element="tns:sayHelloResponse" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="sayHello">
<wsdl:part element="tns:sayHello" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:portType name="IHelloWorld">
<wsdl:operation name="sayHello">
<wsdl:input message="tns:sayHello" name="sayHello"></wsdl:input>
<wsdl:output message="tns:sayHelloResponse" name="sayHelloResponse"></wsdl:output>
</wsdl:operation>
<wsdl:operation name="say">
<wsdl:input message="tns:say" name="say"></wsdl:input>
<wsdl:output message="tns:sayResponse" name="sayResponse"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="HelloWorldImplServiceSoapBinding" type="tns:IHelloWorld">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="sayHello">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="sayHello">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="sayHelloResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="say">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="say">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="sayResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="HelloWorldImplService">
<wsdl:port binding="tns:HelloWorldImplServiceSoapBinding" name="HelloWorldImplPort">
<soap:address location="http://192.168.41.134:8080/CXFSoapDemo/services/HelloWorld"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://lee/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"xmlns:ns1="http://schemas.xmlsoap.org/soap/http" name="HelloWorldImplService" targetNamespace="http://lee/">
<wsdl:operation name="say">
<soap:address location="http://192.168.41.134:8080/CXFSoapDemo/services/HelloWorld"/>
<soap:Envelopexmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body xmlns:tns="http://lee/" >
<tns:sayHello/>
</soap:Body>
</soap:Envelope>
jQuery的ajax请求方法,参见:..\Net\jQuery.docx中ajax部分。
$.ajax({
url :"/CXFSoapDemo/services/HelloWorld",//访问的url
dataType : 'xml',//返回的数据类型
type : 'post',//请求方式
contentType :'application/soap+xml;charset=UTF-8',
data : mySoapXml,//数据
success : function(data,status,
xhr) {
//对返回后的数据进行解析
$(data).find("return").each(
function(index,item){
console.debug(item.innerHTML)
console.debug($(this));
});
},
error : function(xhr, status){
alert("出错了:" +status);
}
});
<!DOCTYPE html>
<html>
<head>
<metacharset="UTF-8">
<title>Insert titlehere</title>
</head>
<scripttype="text/javascript" src="jquery-1.11.3.js"></script>
<body>
<button type="button" id="name">Web服务请求-SOAP</button>
<script type="text/javascript">
$(function() {
$("#name").click(function() {
var mySoapXml = '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"'+
'xmlns:xsd="http://www.w3.org/2001/XMLSchema"'+
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'+
'<soap:Bodyxmlns:lee="http://lee/"><lee:sayHello/></soap:Body></soap:Envelope>';
$.ajax({
url :"/CXFSoapDemo/services/HelloWorld",//访问的url
dataType : 'xml',//返回的数据类型
type : 'post',//请求方式
contentType :'application/soap+xml;charset=UTF-8',
data : mySoapXml,//数据
success : function(data,status,
xhr) {
//对返回后的数据进行解析
$(data).find("return").each(
function(index,item){
console.debug(item.innerHTML)
console.debug($(this));
});
},
error : function(xhr, status){
alert("出错了:" +status);
}
});
});
});
</script>
</body>
</html>
参考:http://blog.csdn.net/etttttss/article/details/17303315
<wsdl:definitions>根:定义当前WebService的地址,名称等。
-|<wsdl:types>数据类型:所有数据和接口类型。
-|<wsdl:message>所有消息的结构。
-|<wsdl:portType>服务接口通信类型:是否具有传入、传出等。
--|<wsdl:operation>服务接口:通信类型。
-|<wsdl:binding>具体协议:具体协议(如SOAP)的使用方法。
--|<wsdl:operation>服务接口:通信的具体实现。
-|<wsdl:service>服务地址集合:定义服务的名称、访问地址等具体使用方法。
--|<wsdl:port>单个服务地址:定义单个服务的地址,binding指明具体的实现方式。
<wsdl:types>
-|<xs:schema>
--|<xs:element>简单定义,供其它部分调用
--|<xs:complexType name="say">详细说明
---|<xs:sequence>列表
----|<xs:element>参数
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://lee/" elementFormDefault="unqualified" targetNamespace="http://lee/" version="1.0">
<xs:element name="say" type="tns:say"/>
<xs:complexType name="say">
<xs:sequence>
<xs:element minOccurs="0" name="arg0" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message>所有消息的结构。
-|<wsdl:part>消息结构,引用types定义。
<wsdl:message name="say">
<wsdl:part element="tns:say" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:portType>
-|<wsdl:operation>:服务接口
--|<wsdl:input>:输入
--|<wsdl:output>:输出
<wsdl:portType name="IHelloWorld">
<wsdl:operation name="say">
<wsdl:input message="tns:say" name="say"></wsdl:input>
<wsdl:output message="tns:sayResponse" name="sayResponse"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding>
-|<soap:binding>
-|<wsdl:operation>
--|<soap:operation />
--|<wsdl:input>
---|<soap:body/>
--|</wsdl:input>
<wsdl:binding name="HelloWorldImplServiceSoapBinding" type="tns:IHelloWorld">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="say">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="say">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="sayResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service>:所有服务在此定义
-|<wsdl:port>:定义单个服务
--|<soap:address >:服务地址
<wsdl:service name="HelloWorldImplService">
<wsdl:port binding="tns:HelloWorldImplServiceSoapBinding" name="HelloWorldImplPort">
<soap:address location="http://192.168.41.134:8080/CXFSoapDemo/services/HelloWorld"/>
</wsdl:port>
</wsdl:service>
//http://192.168.41.134:8080/CXFSoapDemo/services/HelloWorld?wsdl
This XML file does not appearto have any style information associated with it. The document tree is shownbelow.
<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://lee/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" name="HelloWorldImplService"targetNamespace="http://lee/">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://lee/" elementFormDefault="unqualified" targetNamespace="http://lee/" version="1.0">
<xs:element name="say" type="tns:say"/>
<xs:element name="sayHello" type="tns:sayHello"/>
<xs:element name="sayHelloResponse" type="tns:sayHelloResponse"/>
<xs:element name="sayResponse" type="tns:sayResponse"/>
<xs:complexType name="sayHello">
<xs:sequence/>
</xs:complexType>
<xs:complexType name="sayHelloResponse">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="say">
<xs:sequence>
<xs:element minOccurs="0" name="arg0" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="sayResponse">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="sayResponse">
<wsdl:part element="tns:sayResponse" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="say">
<wsdl:part element="tns:say" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="sayHelloResponse">
<wsdl:part element="tns:sayHelloResponse" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="sayHello">
<wsdl:part element="tns:sayHello" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:portType name="IHelloWorld">
<wsdl:operation name="sayHello">
<wsdl:input message="tns:sayHello" name="sayHello"></wsdl:input>
<wsdl:output message="tns:sayHelloResponse" name="sayHelloResponse"></wsdl:output>
</wsdl:operation>
<wsdl:operation name="say">
<wsdl:input message="tns:say" name="say"></wsdl:input>
<wsdl:output message="tns:sayResponse" name="sayResponse"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="HelloWorldImplServiceSoapBinding" type="tns:IHelloWorld">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="sayHello">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="sayHello">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="sayHelloResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="say">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="say">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="sayResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="HelloWorldImplService">
<wsdl:port binding="tns:HelloWorldImplServiceSoapBinding" name="HelloWorldImplPort">
<soap:address location="http://192.168.41.134:8080/CXFSoapDemo/services/HelloWorld"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
服务地址:service下的soap:address 中的location指定。
服务的namespace:wsdl根中targetNameSpace定义。
函数入口:binding找到需要的入口say。
参数:在types中找到say的详细定义,后台complex中参数定义为arg0。
组织soap:
<soap:Envelopexmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body xmlns:lee="http://lee/" >
<lee:say>
<arg0>
client arg0-xx
</arg0>
</lee:say>
</soap:Body>
</soap:Envelope>
示例:参见:示例:同域Web客户端+WebService+带参数的请求
SOAP是xml格式,可以参考XML与JSON转换。
参见:..\Net\jQuery插件-JSON与XML互转.docx
var mySoapXml='<SOAP-ENV:Envelopexmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'+
'<SOAP-ENV:Body>'+
'<tns:findOffLineDaysxmlns:tns="http://webservices.navigation.megaeyes.com/">'+
'<query>'+
'<sessionId>21084</sessionId>'+
'<userGlobalId>1</userGlobalId>'+
'<size>20</size>'+
'<start>0</start>'+
'<companyId>1</companyId>'+
'<endTime>2015-12-16</endTime>'+
'<flag>1</flag>'+
'<licenseNo></licenseNo>'+
'<startTime>2015-12-16</startTime>'+
'<subs>true</subs>'+
'</query>'+
'</tns:findOffLineDays>'+
'</SOAP-ENV:Body>'+
'</SOAP-ENV:Envelope>';
$.ajax({
url :"/OperationStatService",//访问的url
dataType : 'xml',//返回的数据类型
type : 'post',//请求方式
contentType :'application/soap+xml;charset=UTF-8',
data : mySoapXml,//数据
success : function(data, status,
xhr) {
//对返回后的数据进行解析
$(data).find("return").each(
function(index,item) {
var json=$.xml2json(item);
var offLineData=json.offLineData;//处理数据,取出需要的数据组织为easyui需要JSON
createBZXTJ(offLineData);
});
},
error : function(xhr, status) {
alert("出错了:" +status);
}
});
}
$(data).find("return").each(
function(index,item) {
var json=$.xml2json(item);
varoffLineData=json.offLineData;//处理数据,取出需要的数据组织为easyui需要JSON
createBZXTJ(offLineData);
});
$('#bzxtj').propertygrid({
data : offLineData,
scrollbarSize : 0,
columns : [ [ {
field : 'licenseNo',
title : '车牌号'
},
{
field : 'plateColor',
title : '车牌颜色'
},
{
field : 'companyName',
title : '所属企业'
},
{
field : 'offLineDays',
title : '不在线天数'
}] ],
showHeader : true,
showGroup : false
});
//clbzxtj.html
<!DOCTYPE html">
<!--
@author: [email protected]
@date: 2015-9-29 10:52
-->
<html>
<head>
<metacharset="UTF-8">
<title>Insert titlehere</title>
</head>
<body>
<div id="content" class="easyui-layout"data-options="fit:true"
style="width: 100% ;">
<!-- Center Area -->
<div id="center_area"data-options="region:'center',title:''">
<!-- tabs -->
<div title="单车统计">
<!-- data -->
<table id="bzxtj"class="easyui-datagrid"
data-options="fitColumns:true,singleSelect:true"
style="width: 100%;">
</table>
<div class="easyui-pagination"data-options="total:2000,pageSize:10"
style=""></div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
requestWebService();
});
//request web service
function requestWebService(){
var mySoapXml='<SOAP-ENV:Envelopexmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'+
'<SOAP-ENV:Body>'+
'<tns:findOffLineDaysxmlns:tns="http://webservices.navigation.megaeyes.com/">'+
'<query>'+
'<sessionId>21084</sessionId>'+
'<userGlobalId>1</userGlobalId>'+
'<size>20</size>'+
'<start>0</start>'+
'<companyId>1</companyId>'+
'<endTime>2015-12-16</endTime>'+
'<flag>1</flag>'+
'<licenseNo></licenseNo>'+
'<startTime>2015-12-16</startTime>'+
'<subs>true</subs>'+
'</query>'+
'</tns:findOffLineDays>'+
'</SOAP-ENV:Body>'+
'</SOAP-ENV:Envelope>';
$.ajax({
url :"/OperationStatService",//访问的url
dataType : 'xml',//返回的数据类型
type : 'post',//请求方式
contentType :'application/soap+xml;charset=UTF-8',
data : mySoapXml,//数据
success : function(data, status,
xhr) {
//对返回后的数据进行解析
$(data).find("return").each(
function(index,item) {
var json=$.xml2json(item);
varoffLineData=json.offLineData;//处理数据,取出需要的数据组织为easyui需要JSON
createBZXTJ(offLineData);
});
},
error : function(xhr, status) {
alert("出错了:" +status);
}
});
}
function createBZXTJ(offLineData) {
//create cssz
$('#bzxtj').propertygrid({
data : offLineData,
scrollbarSize : 0,
columns : [ [ {
field : 'licenseNo',
title : '车牌号'
},
{
field: 'plateColor',
title : '车牌颜色'
},
{
field : 'companyName',
title : '所属企业'
},
{
field : 'offLineDays',
title : '不在线天数'
}] ],
showHeader : true,
showGroup : false
});
}
</script>
</body>
</html>
//index.html
<!DOCTYPE html>
<html>
<head>
<metacharset="UTF-8">
<title>Insert titlehere</title>
</head>
<scripttype="text/javascript"src="jquery-1.11.3.js"></script>
<body>
<button type="button" id="name">Web服务请求-SOAP</button>
<script type="text/javascript">
$(function() {
$("#name").click(function() {
var mySoapXml = '<soap:Envelopexmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" '+
'xmlns:xsd="http://www.w3.org/2001/XMLSchema"'+
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'+
'<soap:Bodyxmlns:lee="http://lee/"><lee:sayHello/></soap:Body></soap:Envelope>';
$.ajax({
url :"/CXFSoapDemo/services/HelloWorld",//访问的url
dataType: 'xml',//返回的数据类型
type : 'post',//请求方式
contentType :'application/soap+xml;charset=UTF-8',
data : mySoapXml,//数据
success : function(data,status,
xhr) {
//对返回后的数据进行解析
$(data).find("return").each(
function(index,item){
console.debug(item.innerHTML)
console.debug($(this));
});
},
error : function(xhr, status){
alert("出错了:" +status);
}
});
});
});
</script>
</body>
</html>
参见:发布WebService-基于SOAP的Web服务
//index.html
<!DOCTYPE html>
<html>
<head>
<metacharset="UTF-8">
<title>Insert titlehere</title>
</head>
<scripttype="text/javascript"src="jquery-1.11.3.js"></script>
<body>
<button type="button" id="name">Web服务请求-SOAP</button>
<button type="button" id="say">带参数SOAP</button>
<script type="text/javascript">
$(function() {
$("#name").click(function() {
soapCall();
});
$("#say").click(function() {
soapWithArg();
});
});
function soapCall(){
var mySoapXml = '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"'+
'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '+
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'+
'<soap:Body xmlns:lee="http://lee/"><lee:sayHello/></soap:Body></soap:Envelope>';
$.ajax({
url:"/services/HelloWorld",//访问的url
dataType : 'xml',//返回的数据类型
type : 'post',//请求方式
contentType :'application/soap+xml;charset=UTF-8',
data : mySoapXml,//数据
success : function(data, status,
xhr) {
//对返回后的数据进行解析
$(data).find("return").each(
function(index,item) {
console.debug(item.innerHTML)
console.debug($(this));
});
},
error : function(xhr, status) {
alert("出错了:" +status);
}
});
}
functionsoapWithArg(){
var mySoapXml = '<soap:Envelopexmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" '+
'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '+
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'+
'<soap:Bodyxmlns:lee="http://lee/" ><lee:say><arg0>clientarg0-xx</arg0></lee:say></soap:Body></soap:Envelope>';
$.ajax({
url :"/services/HelloWorld",//访问的url
dataType : 'xml',//返回的数据类型
type : 'post',//请求方式
contentType :'application/soap+xml;charset=UTF-8',
data : mySoapXml,//数据
success : function(data, status,
xhr) {
//对返回后的数据进行解析
$(data).find("return").each(
function(index,item) {
console.debug(item.innerHTML)
console.debug($(this));
});
},
error : function(xhr, status) {
alert("出错了:" +status);
}
});
}
</script>
</body>
</html>
参见:发布WebService-基于SOAP的Web服务
请求:request soap
<soap:Envelopexmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Bodyxmlns:lee="http://lee/" ><lee:say><arg0>clientarg0-xx</arg0></lee:say></soap:Body></soap:Envelope>
返回:response soap
<soap:Envelopexmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:sayResponsexmlns:ns2="http://lee/"><return>this is from say(msg)=clientarg0-xx</return></ns2:sayResponse></soap:Body></soap:Envelope>